Getting membership of a user, computer, and group
The function used in this section will help in finding out the group membership of users, computers, or groups. The output of this function is the same as what you will see in the MemberOf tab in the object properties. This function takes two types of input. The first one is the Name
parameter and it takes a list of objects for which you want to query the membership details. The second one is the Type
parameter, which indicates the class of the objects that you supplied to the Name
parameter:
Function Get-ADobjectMembership { [CmdletBinding()] param( [Parameter(Mandatory=$true,Position=0)] [string[]]$Name, [Parameter(Mandatory=$true,Position=1)] [ValidateSet("User","Group","Computer")] [string]$Type ) Foreach($ObjName in $Name) { try { $MemberOf = @(Get-ADObject -Filter { Name -eq $ObjName -and ObjectClass -eq $Type} -Properties MemberOf -EA Stop | select -ExpandProperty MemberOf) if(!$MemberOf) { ...