Last active
August 29, 2015 14:12
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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