Script Repository

Remove values of a multivalued property using regular expressions

February 18, 2021

The script can be used in business rules, custom commands or scheduled tasks to remove values matching a regular expression from a multi-valued property. In the below example, the script will remove all entries ending with from the Email Proxy Addresses property.

To run the script as a part of a business rule, scheduled task, or custom command, you need to use the Run a program or PowerShell script action.


  • $property - Specifies the LDAP display name of the property you want to remove values from.
  • $regex - Specifies the regular expression to use when removing values.
Edit Remove
$property = "proxyAddresses" # TODO: modify me
$regex = "^smtp:[a-zA-Z0-9_.%%\-\+]+@example\.com$" # TODO: modify me

$values = $Context.TargetObject.GetEx($property)
$valuesToRemove = @()
foreach ($value in $values)
    if ($value -cnotmatch $regex)
    $valuesToRemove += $value

if ($valuesToRemove.Length -eq 0)
    return # Nothing to remove

# Update the target object
$Context.TargetObject.PutEx("ADS_PROPERTY_DELETE", $property, $valuesToRemove)

Comments ( 0 )
No results found.
Leave a comment