Script Repository


Remove values of a multivalued property using regular expressions

October 16, 2015
1716

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 )
No results found.
Leave a comment