Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

×
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

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
Mario Carabelli
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Jan 29, 2019

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 

Mario Carabelli
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Jan 29, 2019

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
AUG Leaders

Atlassian Community Events