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.

Script repository

Remove values of a multivalued property using regular expressions

February 18, 2021 Views: 4445

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.
Edit Remove
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()

Comments 0
Leave a comment
Loading...

Got questions?

Support Questions & Answers