Script repository

Update multi-valued property based on regular expression

Updated on: Jan 18, 2026, Views: 7151

Miscellaneous

The script removes values matching a regular expression from a multi-valued property. To execute the script, create a business rule, custom command or scheduled task configured for the required object type.

Parameters

  • $property - the name of the multi-valued property you want to remove values from.
  • $regex - the regular expression to use when removing values.
$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
}

# Update the target object.
$Context.TargetObject.PutEx("ADS_PROPERTY_DELETE", $property, $valuesToRemove)
$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.