Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

1 answer

1 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

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

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

Do you use Jira Cloud with Microsoft Teams?

Hi, Jira users! Do you use Jira alongside Microsoft Teams? We want to hear how you’ve used the power of Jira Cloud and Microsoft Teams (via the Jira Cloud for Microsoft Teams app) to achieve a team...

127 views 2 5
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you