Reputation: 2452
I want to check group membership of a user. Group are taken from an ldap and inserted into a domain. For the moment I tried something like this...
#Powershell.ps1
$CurrentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$wp = New-Object System.Security.Principal.WindowsPrincipal($CurrentUser)
# I have in my domain a group called 'dom_group'
if ( $wp.IsInRole('dom_group') ) {
"Expected to be true"
} else {
"Unexpected False"
}
#Unexpected False
Unfortunately, this works only for local groups.
How can I check the group membership of the current use against the domain group 'dom_group'?
Upvotes: 0
Views: 1610
Reputation: 28789
Your code will work, but you must qualify the group name with the name of your domain: $wp.IsInRole('mydomain\dom_group')
or $wp.IsInRole('dom_group@mydomain')
.
Upvotes: 2