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

Update property value based on the value of another property

December 13, 2024 Views: 21

The script updates a property of the target account based on the value of another property. To execute the script, create a business rule, custom command or scheduled task configured for the required object type.

Parameters:

  • $sourcePropertyName - Specifies the schema name of the property whose value will be used to pick the value for the property to update.
  • $toSetPropertyName - Specifies the schema name of the property to update.
  • $valueMap - maps values of the source property with values of the property to update.
  • $pipelined - Specifies whether to pass the update through the Adaxes pipeline (e.g. to trigger business rules).
Edit Remove
PowerShell
$sourcePropertyName = "title" # TODO: modify me
$toSetPropertyName = "department" # TODO: modify me
$valueMap = @{
    "Account Specialist" = "Accounting"
    "IT Specialist" = "IT"
} # TODO: modify me
$pipelined = $True # TODO: modify me

# Get user property value
try
{
    $propertyValue = $Context.TargetObject.Get($sourcePropertyName)
}
catch
{
    $Context.LogMessage("Property $sourcePropertyName is not specified for user %fullname%.", "Warning")
    return
}

# Get property value
foreach ($item in $valueMap.GetEnumerator())
{
    if ($item.Name -ne $propertyValue)
    {
        continue
    }
    
    $toSetPropertyValue = $item.Value
    
    # Update the user
    $user = $Context.BindToObjectByDNEx("%distinguishedName%", $pipelined)
    $user.Put($toSetPropertyName, $toSetPropertyValue)
    $user.SetInfo()
    break    
}
Comments 0
Leave a comment
Loading...

Got questions?

Support Questions & Answers