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 @example.com 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.
Parameters:
- $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.
PowerShell
$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)
{
continue
}
$valuesToRemove += $value
}
if ($valuesToRemove.Length -eq 0)
{
return # Nothing to remove
}
# Update the target object
$Context.TargetObject.PutEx("ADS_PROPERTY_DELETE", $property, $valuesToRemove)
$Context.TargetObject.SetInfo()