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,455,369
Community Members
 
Community Events
175
Community Groups

Script to remove list / multiple users from a specified group

Edited

I have a scenario where we have a JIRA instance (6.4.7).  I have to do some user management clean up and I'm wanting to be able to run a script (ideally using Scriptrunner) to allow me to remove multiple users from a specified group..

 

Any help would be appreciated

2 answers

1 accepted

3 votes
Answer accepted

Hiya Darren!

You should be able to do something like this:

import com.atlassian.jira.component.ComponentAccessor

def groupManager = ComponentAccessor.groupManager
def userUtil = ComponentAccessor.userUtil
def userManager = ComponentAccessor.userManager

def usersToRemove = ["exampleUser1","exampleUser2","exampleUser3","exampleUser4","exampleUser5"] //User Names
def groupToAlter = groupManager.getGroup("NameOfGroup")

usersToRemove.each{
def currentUser = userManager.getUserByName(it)
userUtil.removeUserFromGroup(groupToAlter, currentUser)
}

Take this script, fill in the user names, fill in the name of the group, and then run it in the Script Console!

Is this close to what you were looking for? :D

Aidan 

Hi @Aidan Derossett [Adaptavist] tried your script in Jira 6.4.13 in script console, getting error :

 

No signature of method: com.atlassian.jira.user.util.UserUtilImpl.removeUserFromGroup() is applicable for argument types: (com.atlassian.crowd.embedded.impl.ImmutableGroup, com.atlassian.jira.user.DelegatingApplicationUser)

 

Pls suggest

Like Hana luiza likes this

That script is for Jira 7+

Jira 6 has different user objects, you'll need to convert it to use applicationuser objects I think.

Like Hana luiza likes this
Niranjan Rising Star Jul 15, 2019

Hi @Nic Brough -Adaptavist- ,

Will this script work for JIRA data center. I executed the script with two users and license count has reduced by 200. How will the script work for groups that has sub-groups? Thanks

Niran

Jira is not aware of sub-groups, it just sees one single list of users in a group.  I suspect it will fail for members of sub-groups.

But, yes, it should work fine for data centre.

Like # people like this

Hello Nic, 

Would this script be able to remove from multiple users in Crowd 2 groups each?

if users on list have let's say jira and confluence to be removed?

Is there a specific API or console to run the script in ?

much thanks 

Yes it can do that if you tweak it a bit to aim at the groups.

It is a Scriptrunner script, so Aiden built it to be run in the SR console

Hi @Aidan Derossett [Adaptavist]

and @Nic Brough -Adaptavist- 

I would like knwo if i can insert the login  in the "@ShortTextInput"

barre.png

and he display me the groups attached to this user and i can the delete this user for all groups he attached

Example 

Login : test12

 

test12 attchdes groups : group1-user ; group2-dveelopers 

Delete the users test 12  so that it us not part of the groups that are displayed

 

i have started the script but i'm blocked 

script_delete.png

 

Thanks in advance

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events