Script Repository


Save list of group members to multi-valued property

January 29, 2021
1218

The script saves a list of members of an AD group to a multi-valued property of the group. The list includes both direct and indirect group members.

Parameter:

  • $membersProperty - specifies the LDAP name of the AD property that stores the member list. For this purpose, we recommend using an Adaxes virtual property, e.g. CustomAttributeMultiValue1. Such properties are not stored in AD, but can be used the same as any other properties of AD objects.
Edit Remove
PowerShell
$membersProperty = "adm-CustomAttributeTextMultiValue1" # TODO: modify me

$groupMemberList = @()

# Get group members
try
{
    $memberGuidsBytes = $Context.TargetObject.GetEx("adm-MembersGuid")
}
catch
{
    $memberGuidsBytes = $NULL # The group has no members
}


# Get member names
if ($memberGuidsBytes -ne $NULL)
{
    foreach ($memberGuidBytes in $memberGuidsBytes)
    {
        $memberGuid = New-Object "System.Guid" (, $memberGuidBytes)
        $memberGuid = $memberGuid.ToString("B")
        $memberPath = "Adaxes://<GUID=$memberGuid>"
        $member = $Context.BindToObject($memberPath)
        $memberName = [Softerra.Adaxes.Utils.ObjectNameHelper]::GetObjectName($member, 'IncludeParentPath')
        $groupMemberList += $memberName
    }
}

# Save to property
$Context.TargetObject.Put($membersProperty, $groupMemberList)
$Context.TargetObject.SetInfo()

Comments ( 0 )
No results found.
Leave a comment

Related Scripts