You can now vote for scripts to help people know if they're useful or not. Login or create an account to vote!

1

Deactivate Users

Overview

Run this script in the Script Console to deactivate specified users. Use this script to deactivate multiple users with one action, saving time manually finding and deleting users.

Example

I have received a list of users who have left the company from our HCM system. For system security, I need to remove these users as soon as possible. Usually, I would need to search for each name individually and manually delete each user. With this script, I can enter the list of user names and bulk delete all of them with one action.

Good to Know

If any users from the list cannot be deactivated (for instance if they are currently a component lead) a message will be logged. You can then fix this and re-run your script. No harm will come from deactivating a user that is already inactive.

Requirements

  • Jira Jira (8.0 - 8.14)
  • ScriptRunner for Jira ScriptRunner for Jira (6.18.0)
    
import com.atlassian.jira.bc.user.UserService import com.atlassian.jira.component.ComponentAccessor def userManager = ComponentAccessor.userManager def userService = ComponentAccessor.getComponent(UserService) [ 'anuser', 'otheruser', // add more as required ].each { username -> def user = userManager.getUserByName(username) if (!user) { log.warn "Failed to find user with name ${username}" return } def updatedUser = userService.newUserBuilder(user).active(false).build() def updateUserValidationResult = userService.validateUpdateUser(updatedUser) if (updateUserValidationResult.valid) { log.warn "Deactivating user ${username}" userService.updateUser(updateUserValidationResult) } else { log.warn "Update of ${user.name} failed: ${updateUserValidationResult.errorCollection.errors.entrySet().join(',')}\n" } }
Discovered an issue? Report it here

Suggested for you