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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you use the cloud version, and want similar feature, can you vote for: https://jira.atlassian.com/browse/CONFCLOUD-65844
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.