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?
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.