Last active
May 11, 2018 16:34
-
-
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
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
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