Skip to content

Instantly share code, notes, and snippets.

@davegreen
Last active December 18, 2015 20:49
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save davegreen/5842924 to your computer and use it in GitHub Desktop.
A quick function to get groups that the current user is a member of.
# Gets a list of groups that the user is a member of from the current Windows identity token.
# Param1: $domain - Boolean value. Return group names with domain or not.
# e.g. true = "BUILTIN\Authenticated Users", false = "Authenticated Users".
Function Get-Membership($domain)
{
$groups = @()
foreach ($group in [System.Security.Principal.WindowsIdentity]::GetCurrent().Groups)
{
$grp = $group.Translate([System.Security.Principal.NTAccount]).ToString()
if (($grp -like ("*\*")) -and (!$domain))
{
$groups += $grp.Substring((($grp.IndexOf("\")) + 1))
}
else
{
$groups += $grp
}
}
return $groups
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment