AEM User Report

Handy Groovy scripts
How to fetch the list of users belong to specific user groups? Here you go –
// List users belong to specific groups
groups = [‘group-name-1’, ‘group-name-2’, ‘group-name-3’, ‘group-name-4’]
def userManager = resourceResolver.adaptTo(org.apache.jackrabbit.api.security.user.UserManager.class)
def getUserProperty(user, property) {
def values = user.getProperty(‘profile/’ + property);
return values != null && values.size() > 0 ? values[0].getString() : ”
}
println “Group ID – User ID – FirstName LastName – Email”
groups.each { groupId ->
def group = userManager.getAuthorizable(groupId)
if (group != null) {
group.members.each { member ->
if (!member.group) {
def givenName = getUserProperty(member, ‘givenName’)
def familyName = getUserProperty(member, ‘familyName’)
def email = getUserProperty(member, ’email’)
println “${group.ID} – ${member.ID} – ${givenName} ${familyName} – ${email}”
}
}
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s