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

Script to remove list / multiple users from a specified group

Darren Campbell September 20, 2017

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

Suggest an answer

Log in or Sign up to answer
3 votes
Answer accepted
Aidan Derossett _Adaptavist_
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.
September 21, 2017

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 

Hemanshu Sood July 16, 2018

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 Deleted user likes this
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 16, 2018

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 Deleted user likes this
Niranjan
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.
July 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

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 15, 2019

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
Deleted user March 4, 2021

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 

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 4, 2021

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

0 votes
Salim Hammar June 24, 2022

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

TAGS
AUG Leaders

Atlassian Community Events