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,296,430
Community Members
 
Community Events
165
Community Groups

Script to remove Inactive users who have never logged in

My company copied users from an AD database to a Jira Internal database.  I now have literally thousands of "extra" user accounts for users who are Inactive and have never logged in to Jira.  I would like to delete these users from the Jira Internal database.  I have ScriptRunner, and simply need help with a script.  Anyone willing to give it a shot and help me out?

I did try a script I found to at least strip their group assignments away, and although I got no errors, that script didn't work.  All the Inactive users are all still assigned to various groups.  Here's the info on that:  https://community.atlassian.com/t5/Jira-questions/ScriptRunner-script-to-remove-inactive-users-from-all-groups/qaq-p/632587?utm_source=atlcomm&utm_medium=email&utm_campaign=immediate_general_reply&utm_content=topic#U2012433

Would really appreciate some guidance!

2 answers

Hi @kdickason,

you can do it with this script:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.login.LoginManager

def loginManager = ComponentAccessor.getComponent(LoginManager.class);
def adminUser = ComponentAccessor.userManager.getUserByName("admin") // Replace "admin" with an administrator username
def userUtil = ComponentAccessor.userUtil

ComponentAccessor.userManager.allUsers.each{ it->
if (loginManager.getLoginInfo(it.username).loginCount == null) {
log.error "User never logged in: " + it.username
//userUtil.removeUser(adminUser, it) // Uncomment this row to enable removal
}
}

This is wonderful for you to provide.  But please allow me to ask -- what would I need to add to this script so it would only remove INACTIVE users who have never logged in? I would like to keep Active accounts who have never logged in for now. @Andrea Pannitti 

@kdickason you could change the code like this:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.login.LoginManager

def loginManager = ComponentAccessor.getComponent(LoginManager.class);
def adminUser = ComponentAccessor.userManager.getUserByName("admin") // Replace "admin" with an administrator username
def userUtil = ComponentAccessor.userUtil

ComponentAccessor.userManager.allUsers.findAll{ !it.isActive() && loginManager.getLoginInfo(it.username).loginCount == null }.each{ it->
log.error "User inactive and never logged in: " + it.username
//userUtil.removeUser(adminUser, it) // Uncomment this row to enable removal
}

 

Hi @kdickason 

 

I don't have a script but we are using Manage Inactive Users for Jira add-on to remove the never logged-in users from our system.

 

Thanks,

Tushar

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you