Script Repository


Multi-valued property values

April 01, 2021
283

The script generates a report that will include users multiple times depending on the number of values in the specified multi-valued property. The property values will be added to a custom column.

Parameters:

  • $columnID - Specifies the identifier of the custom column that will be used to store values of the specified multi-valued property. To get the identifier:
    1. On the Columns tab, right-click the custom column in the Report-specific columns section.
    2. In the context menu, navigate to Copy and click Column ID.
    3. The identifier will be copied to clipboard.
  • $propertyName - Specifies the LDAP name for the multi-valued property whose values will be added to the custom column.
Edit Remove
PowerShell
$columnID = "{a8152795-c240-4317-b1ad-09fab4822abd}" # TODO: modify me
$propertyName = "adm-CustomAttributeTextMultiValue1" # TODO: modify me

# Build search filter
$Context.DirectorySearcher.AppendFilter("(sAMAccountType=805306368)")

try
{
    $Context.DirectorySearcher.SearchParameters.PropertiesToLoad.Add($propertyName)
    $searchIterator = $Context.DirectorySearcher.ExecuteSearch()
    
    while ($Context.MoveNext($searchIterator))
    {
        $searchResult = $searchIterator.Current
        $searchResultProperty = $searchResult.GetPropertyByName($propertyName)
        
        if ($searchResultProperty.Values.Count -eq 0)
        {
            $Context.Items.Add($searchResult, @{ $columnID = $NULL }, $NULL )
        }
        else
        {
            foreach ($value in $searchResultProperty.Values)
            {
                $clonedSearchResult = $searchResult.Clone($False)
                $Context.Items.Add($clonedSearchResult, @{ $columnID = $value }, $NULL )
            }
        }
    }
}
finally
{
    # Release resources
	if ($searchIterator) { $searchIterator.Dispose() }
}

Comments ( 0 )
No results found.
Leave a comment