Tests if a user or group is a member of a local group.
Test-GroupMember [-GroupName] <String> [-Member] <String> [<CommonParameters>]
The Test-GroupMember
function tests if a user or group is a member of a local group using .NET's DirectoryServices.AccountManagement APIs. If the group or member you want to check don't exist, you'll get errors and $null
will be returned. If Member
is in the group, $true
is returned. If Member
is not in the group, $false
is returned.
The user running this function must have permission to access whatever directory the Member
is in and whatever directory current members of the group are in.
This function was added in Carbon 2.1.0.
Name | Type | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
GroupName | String | The name of the group whose membership is being tested. |
true | false | |
Member | String | The name of the member to check. |
true | false |
Test-GroupMember -GroupName 'SithLords' -Member 'REBELS\LSkywalker'
Demonstrates how to test if a user is a member of a group. In this case, it tests if REBELS\LSkywalker
is in the local SithLords
, which obviously he isn't, so $false
is returned.