Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,457,003
Community Members
 
Community Events
176
Community Groups

Script to remove a list of users from all groups

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

2 answers

1 accepted

0 votes
Answer accepted

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

Mario,

That's brilliant, works a treat. Many thanks.

Peter 

Hi @Peter Ellis,

good  idea to create a script for this usecas!

I will use this myself :)

With kind regards
Mario

Hi @Mario Carabelli,

Would you know how to deactivate the user too?

Best regards

Peter

Hi @Mario

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

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events