Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Bulk remove users from a group

Spruha Shah October 11, 2023

Hi, 

 

Can you help me with a script that i can run through scriptrunner console to remove a list of users from a group in confluence? 

 

 

3 answers

0 votes
Kieren _SmolSoftware_
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.
April 2, 2025

Another option that’s a bit less work, use an app like Admin Automations to bulk remove users from groups.

0 votes
Ramanji Alugula April 2, 2025

Hi @Spruha Shah @Dario ,

I have been using the script below to remove users from Confluence groups, and it has worked great for me:

import com.atlassian.confluence.user.UserAccessor
import com.atlassian.confluence.user.ConfluenceUser
import com.atlassian.user.Group
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.user.search.page.Pager

// Retrieve the UserAccessor instance
def userAccessor = ComponentLocator.getComponent(UserAccessor)

// List of users to be removed from groups (usernames)
List<String> users = ["User1", "User2", "User3"]

def removeUserFromSpecificGroups(UserAccessor userAccessor, String username) {
ConfluenceUser user = userAccessor.getUserByName(username)
if (user) {
// Get all groups the user belongs to
Pager<Group> userGroupsPager = userAccessor.getGroups(user)
userGroupsPager.each { group ->
if (group.getName() == "group1" || group.getName() == "group2" ) {
// Cast user and group to the expected types
def confluenceUser = user as ConfluenceUser
def confluenceGroup = group as Group
userAccessor.removeMembership(confluenceGroup, confluenceUser)
log.info("Successfully removed ${username} from ${group.getName()}")
}
}
} else {
log.warn("User ${username} not found")
}
}

// Remove users from "group1" and "group2" groups
users.each { user ->
removeUserFromSpecificGroups(userAccessor, user)
}



Ramanji

0 votes
Dario February 2, 2024

Hi Community,

I have the same question.

How to remove all confluence users from a specific confluence group using groovy script? I have been looked into in the documentation but there is nothing related to.

Thank you in advance.

Dario

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events