Another option that’s a bit less work, use an app like Admin Automations to bulk remove users from groups.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.