Skip to content

Instantly share code, notes, and snippets.

@JackGruber
Last active May 11, 2018 16:34
Show Gist options
  • Save JackGruber/64aa088e0b52db15ef7ab185313974aa to your computer and use it in GitHub Desktop.
Save JackGruber/64aa088e0b52db15ef7ab185313974aa to your computer and use it in GitHub Desktop.
Get locale and domain group membership from current user without AD powershell module
function Get-Groups {
Param(
[string]$isMember
)
if($isMember)
{
$mytoken = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$me = New-Object System.Security.Principal.WindowsPrincipal($mytoken)
return $me.IsInRole($isMember)
}
else
{
$user_token = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$groups = New-Object System.Collections.ArrayList
foreach($group in $user_token.Groups)
{
[void] $groups.Add( $group.Translate("System.Security.Principal.NTAccount") )
}
return $groups
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment