Script repository

Remove values for deleted objects from a DN-syntax property

Updated on: Jan 18, 2026, Views: 3442

Miscellaneous

The script removes records for deleted objects from a DN-syntax property. To execute the script, create a business rule, custom command or scheduled task configured for the required object type.

In the script, the $propertyName variable specifies the name of the property to update.

$propertyName = "secretary" # TODO: modify me

# Get current property values.
try
{
    $values = $Context.TargetObject.GetEx($propertyName)
}
catch
{
    $Context.LogMessage("The $propertyName property is empty for %fullname%.", "Information")
    return
}

# Remove records for deleted objects.
$newValues = New-Object System.Collections.ArrayList
foreach ($value in $values)
{
    if($value -notlike "*DEL:*,CN=Deleted Objects,*")
    {
        $newValues.Add($value)
    }
}

# Update the property
$Context.TargetObject.PutEx("ADS_PROPERTY_UPDATE", $propertyName, @($newValues))
$Context.TargetObject.SetInfo()

Comments 0

You must be signed in to comment.

    Got questions?

    Support Questions & Answers

    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.