We use cookies to improve your experience.
By your continued use of this site you accept such use.
For more details please see our privacy policy and cookies policy.

Script Repository

Update allowed values property pattern based on group members

September 04, 2023 Views: 1181

The script updates the list of values allowed for a DN syntax property by a property pattern with members of groups. To run the script, create a scheduled task configured for the Domain-DNS object type and add a managed domain to the Activity Scope. The domain will only be used to trigger execution of the scheduled task. The search criteria are specified in the script.


  • $groupDNs - Specifies distinguished names (DNs) of the groups whose members will be set as allowed property values.
  • $isPropertyRequired - Specifies whether the property should be set as required in the property pattern.
  • $patternName - Specifies the distinguished name (DN) of the property pattern to update.
  • $propertyName - Specifies the name of the property for which the list of allowed values will be updated in a property pattern.
Edit Remove
$groupDNs = @("CN=Group 1,OU=Groups,DC=domain,DC=com", "CN=Group 2,OU=Groups,DC=domain,DC=com") # TODO: modify me
$patternDN = "CN=User,CN=Builtin,CN=Property Patterns,CN=Configuration Objects,CN=Adaxes Configuration,CN=Adaxes" # TODO: modify me
$propertyName = "seeAlso" # TODO: modify me
$isPropertyRequired = $True # TODO: modify me

# Get member GUIDs
$allMemberGuidBytes = New-Object "System.Collections.Generic.HashSet[Byte[]]"
foreach ($groupDN in $groupDNs)
        $group = $Context.BindToObjectByDN($groupDN)
        $memberGuidsBytes = $group.GetEx("adm-DirectMembersGuid")

    $memberGuidsBytes | %% { [void]$allMemberGuidBytes.Add($_) }

if ($allMemberGuidBytes.Count -eq 0)
    $Context.LogMessage("Groups have no members.", "Warning")

# Search parameters
$searcher = $Context.CreateGuidBasedSearcher(@($allMemberGuidBytes))
$criteriaUser = New-AdmCriteria "user"

    # Execute search
    $searchResultIterator = $searcher.ExecuteSearch()
    $searchResults = $searchResultIterator.FetchAll()
    if ($searchResults.Length -eq 0)
        $Context.LogMessage("Groups have no members that are users.", "Warning")
    $memberDNs = New-Object System.Collections.ArrayList
    foreach ($searchResult in $searchResults)
    # Release resources
    if ($searchResultIterator){ $searchResultIterator.Dispose() }

# Bind to the property pattern.
$pattern = $Context.BindToObjectByDN($patternDN)

# Delete item for property.
foreach ($item in $pattern.Items)
    if ($item.PropertyName -ieq $propertyName)

# Create a new item for property.
$item = $pattern.Items.Create()
$item.PropertyName = $propertyName
$item.IsPropertyRequired = $isPropertyRequired

$constraints = $item.GetConstraints()
$constraint = $constraints.Create("ADM_PROPERTYCONSTRAINTTYPE_VALUERANGE")
$constraint.AreValuesDenied = $False
$constraint.Values = $memberDNs.ToArray()

# Save the changes

Comments 0
Leave a comment

Got questions?

Support Questions & Answers