Skip to content

Instantly share code, notes, and snippets.

@mortenya
Last active August 29, 2015 14:12
Show Gist options
  • Save mortenya/3a2c208c92ca0e64c597 to your computer and use it in GitHub Desktop.
Save mortenya/3a2c208c92ca0e64c597 to your computer and use it in GitHub Desktop.
Just one way to get the names, (CN), of the groups that an ADUser is a member of.
(Get-ADUser –Identity $user –Properties MemberOf).MemberOf -replace '^CN=([^,]+),OU=.+$','$1' > c:\user-groups.txt
# The -replace will strip the CN of the group from the Distinguished Name.
# This isn't error proof, but will be adequate for most use cases when dealing with Security Groups.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment