Hello all,
We got several spam accounts in our internal directory with same full name. We need to bulk delete all of them.
Is there a way we could get list of Users using full name and deleting them using a loop in ScriptRunner?
Hello @kiran kumar
Try the following
import com.atlassian.jira.bc.user.UserService
import com.atlassian.jira.bc.user.search.UserSearchService
import com.atlassian.jira.component.ComponentAccessor
def userServise = ComponentAccessor.getComponent(UserService)
def userSearchServise = ComponentAccessor.getComponent(UserSearchService)
def adminUser = ComponentAccessor.userManager.getUserByName('AdminUserName')
def users = userSearchServise.findUsersByFullName('FullName')
users.each {
def result = userServise.validateDeleteUser(adminUser, it)
if (result.valid) userServise.removeUser(adminUser, result)
}
Thanks a lot, Yuri!
Just one correction, getUserByName did not work, so I have used getUserByKey.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.