Script Repository


Create LDAP filter to find all objects managed by user

September 14, 2017
2227

The script creates an LDAP filter that allows finding all objects managed by the user on which the script is executed and saves it to a certain attribute of the user account. The filter will include both objects managed by the user directly and objects managed via membership in AD groups.

Note: Users are assigned to manage an AD object via the Managed By property of the object.

Parameter:

  • $propertyForFilter - specifies the LDAP display name of the property that will be used to store the LDAP filter.

To create the LDAP filter for any user on demand, create a Custom Command that can be executed on User objects and execute it on the users you need. To keep up with changes in your Active Directory, create a Scheduled Task to update the filters of users on a regular basis.

Edit Remove
PowerShell
$propertyForLDAPFilter = "adm-CustomAttributeText1" # TODO: modify me

try
{
    # Get GUIDs of all objects managed by the user
    $managedObjectGuids = $Context.TargetObject.GetEx("adm-ManagedObjectsGuid")
}
catch
{
    # Set an empty GUID as the filter so no objects are returned
    $Context.TargetObject.Put($propertyForLDAPFilter, "(objectGuid=\00)")
    $Context.TargetObject.SetInfo()
    return
}

# Build filter
$ldapFilter = New-Object "System.Text.StringBuilder"
[Void]$ldapFilter.Append("(|")
foreach ($guid in $managedObjectGuids)
{
    $filterPart = [Softerra.Adaxes.Ldap.FilterBuilder]::Create("ObjectGuid", $guid)
    [Void]$ldapFilter.Append($filterPart)
}
[Void]$ldapFilter.Append(")")

# Save filter to the property specified
$Context.TargetObject.Put($propertyForLDAPFilter, $ldapFilter.ToString())
$Context.TargetObject.SetInfo()

The script can be used to build a Business Unit that will present each user with a list of all their managed objects. For information on how to create such a Business unit, see Example 3 under Query Results in Group AD Objects Based on Logged In User.

For the LDAP filter, specify a value reference for the property that you used in $propertyForFilter. For example, if you specified adm-CustomAttributeText1, use the following value reference: %adm-CustomAttributeText1%.

See Also:


Comments ( 0 )
No results found.
Leave a comment