Testing Group Membership

Using the Test-EmdbGroupMember cmdlet you can test objects for membership in Static, Dynamic and External Groups. The cmdlet returns true if the test succeeds and false when it fails.


Note: The cmdlet Test-EmdbGroupMember is not only testing for membership in Static Groups but for membership in Group objects of all kinds.


Examples:


Hint: The execution of these examples requires a connected PowerShell drive.


The following code-snippet tests, if the computer "WIN10-02" is member of the static computer group "Greenshot":


$MyGroup = Get-EmdbGroup "emdb:\rootDSE\Managed Users & Computers\solys.local\Greenshot"

$MyComputer = Get-EmdbComputer "emdb:\rootDSE\Managed Users & Computers\solys.local\Chicago\ITService\Workstations\WIN10-02"

Test-EmdbGroupMember -Group $MyGroup -Member $MyComputer


This one tests, if the user object "Adam Sam" is member of the External Group "Domain Admins". In this example, the objects are not retrieved and then used in the command but are referenced using their full qualified path in the ODS:


Test-EmdbGroupMember -Group "emdb:\rootDSE\Managed Users & Computers\solys.local\Domain Admins" -Member "emdb:\rootDSE\Managed Users & Computers\solys.local\Chicago\ITService\Users\Adam Sam"


You can also specify the Any-switch to test, if at least one of the objects is member of the specified group, as the following example shows:


$MyUsers = Get-EmdbUser "emdb:\rootDSE\Managed Users & Computers\solys.local\Chicago\ITService\Users\*"

$MyGroup = Get-EmdbGroup "emdb:\rootDSE\Managed Users & Computers\solys.local\Chicago\Solys User"

Test-EmdbGroupMember -Group $MyGroup -Member $MyUsers -Any