Hi,
I have some regular user management clean up where I need to remove a list of users from all the groups that they are in. Jira server v7 and using ScriptRunner Script Console. Can anyone help?
Much appreciated
Hi @Peter Ellis,
this script uses the Jira API 7.6.1 and worked on my system (Jira Server 7.9).
import com.atlassian.jira.component.ComponentAccessor
List<String> userNames = ["testuser"] // add all usernames in this array where you want to remove the groups
def userUtil = ComponentAccessor.getUserUtil()
def userManager = ComponentAccessor.getUserManager()
for (String userName in userNames) {
def groups = userUtil.getGroupsForUser(userName)
def user = userManager.getUserByName(userName)
for (def group in groups) {
userUtil.removeUserFromGroup(group, user)
}
}
With kind regards,
Mario
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Peter Ellis,
good idea to create a script for this usecas!
I will use this myself :)
With kind regards
Mario
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.
Hi @[deleted]
nice script:-)
Due to performance reasons I modified it as shown... (changed removeUserFromGroup to removeUserFromGroups)
import com.atlassian.jira.component.ComponentAccessor
List<String> userNames = ["TestUser"] // add all usernames in this array where you want to remove the groups
def userUtil = ComponentAccessor.getUserUtil()
def userManager = ComponentAccessor.getUserManager()
for (String userName in userNames) {
def groups = userUtil.getGroupsForUser(userName)
def user = userManager.getUserByName(userName)
userUtil.removeUserFromGroups(groups, user)
}
Cheers
Heiko
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Heiko Gerlach and @Mario Carabelli
I need the help in this question : https://community.atlassian.com/t5/Jira-questions/Get-and-remove-all-groups-from-User-in-Crowd/qaq-p/2158148
you can help me please
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.