Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

De-activate Bulk Users Jira

Hemanshu Sood
Contributor
July 16, 2018

I have a list of 200 + users which I need to de-activate in my Jira instance. Can this be done with the help of a groovy script. Please suggest

2 answers

1 accepted

1 vote
Answer accepted
Marcos Sanchez
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 16, 2018

Hi!

 

You can bulk disable users with this script, you only have to add the username to the "users" array. Also you should check that you have an "admin" user or set the administrator username for the "admin" variable

import com.atlassian.crowd.embedded.impl.ImmutableUser
import com.atlassian.jira.bc.user.UserService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUsers

//Add usernames here
def users = []

def userManager = ComponentAccessor.userManager
def userService = ComponentAccessor.getComponent(UserService)
def jiraAthenticationContext = ComponentAccessor.jiraAuthenticationContext

//You have to change the value "admin" for your admin user.
def admin = userManager.getUserByName("admin")
jiraAthenticationContext.setLoggedInUser(admin)

users.each{ username ->
def userToDisable = userManager.getUserByName(username)
def userToDisableFromDirectory = ApplicationUsers.toDirectoryUser(userToDisable)
def updateUser = ApplicationUsers.from(ImmutableUser.newUser(userToDisableFromDirectory).active(false).toUser())
def updateUserValidationResult = userService.validateUpdateUser(updateUser)
if (updateUserValidationResult.isValid()) {
userService.updateUser(updateUserValidationResult)
}
}

 

I don't know if there's a better script for that, by I've always used this one.

Hope it helps!

 

Regards,

Marcos

Hemanshu Sood
Contributor
July 16, 2018

Thanks @Marcos Sanchez, it works.

0 votes
Taiji Okada March 18, 2019

If you use the cloud version, and want similar feature, can you vote for: https://jira.atlassian.com/browse/CONFCLOUD-65844

Suggest an answer

Log in or Sign up to answer