Skip to content

Instantly share code, notes, and snippets.

@randomvariable
Created August 29, 2013 16:00
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 randomvariable/6380009 to your computer and use it in GitHub Desktop.
Save randomvariable/6380009 to your computer and use it in GitHub Desktop.
Check if a user is a member of a group
# Create a Windows Identity Principal (note the cast)
$principal = [Security.Principal.WindowsPrincipal](new-object System.Security.Principal.WindowsIdentity("<username>@<domain>"))
# Check if it is a member of a group
$princial.IsInRole("<domain>\<group name>")
# Other useful things you can do:
$identity = (new-object System.Security.Principal.WindowsIdentity("<username>@<domain>"))
# Token size
$identity.Token
# Groups
$identity.Groups
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment