Skip to content

Instantly share code, notes, and snippets.

@badvision
Last active March 8, 2016 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save badvision/64ba0db6f670d533bfcc to your computer and use it in GitHub Desktop.
Save badvision/64ba0db6f670d533bfcc to your computer and use it in GitHub Desktop.
AEM Group membership extractor, use with buildGroupMatrix to produce a spreadsheet of all users and what groups they're in
// Step 1: retrieve group list via http://AEMINSTANCE:4502/home/groups.xml and save as group.xml
// Step 2: modify this script (find/replace AEMINSTANCE:4502 with your AEM host/port, also USERNAME and PASSWORD)
// Stpe 3: run this script in the same directory as group.xml
// Step 4: make the output groups_retrieve.sh executable and run it
// Step 5: use the buildGroupMatrix.groovy script to render the spreadsheet
def groupXml = 'groups.xml' as File
def outScript = 'groups_retrieve.sh' as File
def allGroups = new XmlSlurper().parseText(groupXml.getText())
pathBuilder = {node, path="" ->
node.name() == "groups" ? path.substring(0,path.length()-1) : pathBuilder.trampoline(node.parent(), node.name() + "/" + path)
}.trampoline()
allGroups.'**'.findAll{node ->
node["@jcr:primaryType"]=="rep:Group" && // Note: You can add/change filtering logic to leave out groups you don't want to track here
!node.name().startsWith("mac-default") &&
!node.name().startsWith("projects-")
}.each{outScript << "curl -u USERNAME:PASSWORD http://AEMINSTANCE:4502/home/groups/${pathBuilder(it)}.rw.json?props=* > group_${it.name()}.json\n"}
""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment