Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,642,208
Community Members
 
Community Events
196
Community Groups

Need script to remove 60-day inactive users from jira-users group

I am not a strong script writer so I am looking for someone to provide me a script that I can run each night to look for users who have not logged in in the last 60 days and remove them from the jira-users group so they no longer take a license up.  I have ScriptRunner. I have found other scripts out there to de-activate users, but those scripts don't work for me because of our AD/LDAP setup.  So I just want to remove the inactive from the jira-users group.  I would be SO GREATFUL for someone to provide me a script to do this by username.  We have Jira 8.19.

3 answers

1 accepted

0 votes
Answer accepted

@Mirco Fabbri Provided the answer in a different write up:   https://community.atlassian.com/t5/Adaptavist-questions/Scriptrunner-deactivate-inactive-users-script-needs-to-be/qaq-p/914110?utm_source=atlcomm&utm_medium=email&utm_campaign=immediate_general_reply&utm_content=topic 

 Here is the script he provided...

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.login.LoginManager
import java.text.SimpleDateFormat;
import com.atlassian.crowd.embedded.api.CrowdService
import com.atlassian.crowd.embedded.api.UserWithAttributes
import com.atlassian.jira.bc.user.UserService
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.event.type.EventDispatchOption


def userUtil = ComponentAccessor.userUtil
def userManager = ComponentAccessor.userManager
def groupManager = ComponentAccessor.getGroupManager();
def loginManager = ComponentAccessor.getComponentOfType(LoginManager.class)
CrowdService crowdService = ComponentAccessor.crowdService
def maxDays = 90 // maximum number of days you will allow

 

def excludedGroups = [ // only externals
"jira-administrators",
"jira-system-administrators"
]

 

long count = 0;
def list
def lastlogin
def output = "Display Name; Username; Email; Last Login <br>"
def today = new Date()
def lastLogin
SimpleDateFormat df = new SimpleDateFormat("dd.MM.yy hh:mm")
userManager.getUsers().each { // loop through every user
list = true;
groupManager.getGroupNamesForUser(it).each { // loop through his groups
if (excludedGroups.contains(it)) { // if at least one group is in the list, add user
list = false;
}
}
if(list && it.isActive()) { //check if user is active & supposed to be listed
UserWithAttributes user = crowdService.getUserWithAttributes(it.getName())
Long lastLoginTime = loginManager.getLoginInfo(it.username).getLastLoginTime()
lastlogin = "Never Logged In"
if(lastLoginTime != null) {
Date date = new Date(lastLoginTime)
lastlogin = df.format(date)
}
if(lastLoginTime != null && groovy.time.TimeCategory.minus(new Date(), new Date(lastLoginTime)).days > maxDays) {
userUtil.removeUserFromGroup(ComponentAccessor.groupManager.getGroup("jira-software-user"), it)
output += "${it.getDisplayName()}; ${it.getUsername()}; ${it.getEmailAddress()}; ${lastlogin};<br>"
count++
}
}
}
output

Hi @kdickason 
Glad you asked this,


you can consider using the miniOrange Bulk User management plugin for JIRA.
There, you can find a variety of features regarding user management such as deactivating inactive users (the same requirement you have), you can also perform bulk operations on the users (which native Jira user management does not support) You can import or export users and auto deactivate users who have never logged in. On top of that, if you need
any custom features, we also provide tailor-made solutions just for your requirements.
Check out the plugin here. https://marketplace.atlassian.com/apps/1224360/mo-bulk-user-management-deactivate-inactive-users-for-jira?hosting=datacenter&tab=overview

1 vote
Fazila Ashraf
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Oct 26, 2021

Hi @kdickason 

You can refer to https://library.adaptavist.com/entity/remove-specified-users-from-a-group and tweek it for removing the users from the group jira-users 

To get the inactive users, as mentioned in the page, you can refer to https://library.adaptavist.com/entity/deactivate-idle-users to get the list of users with some more tweeks.

Hi @Fazila Ashraf ,

Is it possible to get inactive users in Jira Cloud using the script Runner addon?

Regards,

Prasad E

Like Olivia Case likes this
Fazila Ashraf
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jan 17, 2022

Haven't done that in cloud but a quick search got me this free plugin that could help with this use case https://marketplace.atlassian.com/apps/1224410/manage-users-for-jira-cloud?tab=overview&hosting=cloud

 

Hope it helps... Let me know

Hi @Prasad Eda ,

Did you find/created the script to inactive users in Jira Cloud using the script Runner addon? 

I am also looking for the same in Jira cloud using Script Runner.

Thanks,

Alok

Like Olivia Case likes this

Same - looking for this Jira Cloud version of the Script Runner code. 

 

Looking through Adaptavist library there aren't many scripts for the cloud. 

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Dec 29, 2022

You can't do this in Jira Cloud - users and groups are maintained in Atlassian Access, or Atlassian Admin if you don't have Access.  You would need to look for a solution that can do site admin.

Like Alok Kumar likes this

Darn - thanks Nic.

Like Nic Brough -Adaptavist- likes this

Hi @Olivia Case

If you're looking for an easy way to automatically deactivate inactive users, you can install this app from the marketplace:

Auto Users Management 

 

It will deactivate all inactive users you have periodically by the time you choose.

It's secure and uses Atlassian's Api's only

Suggest an answer

Log in or Sign up to answer