Script repository
The script updates two properties based on the value of a specific property. To execute the script, create a business rule, custom command or scheduled task configured for the required object type.
Parameter
$basePropertyName- the name of the property whose values will be used as base for the update.$valueMap- maps values of the property specified in the$basePropertyNamevariable with names of the properties to be updated and their values.
$basePropertyName = "departmentNumber" # TODO: modify me
$valueMap = @{
"01234" = @{
"l" = "City1";
"st" = "State1";
};
"57890" = @{
"l" = "City2";
"st" = "State2"
};
} # TODO: modify me. Example @{<base property value> = <Property map>}.
# $valueMap = @{"0001" = @{"l" = "City"; "department" = "Dep1"; "st" = "State"}}
# Get base property value,
try
{
$baseValue = $Context.TargetObject.Get($basePropertyName)
}
catch
{
return
}
# Update properties
$propertyMap = $valueMap[$baseValue]
if ([System.String]::IsNullOrEmpty($propertyMap))
{
$Context.LogMessage("Properties to update not specified for '$baseValue' value", "Warning")
return
}
$user = $Context.BindToObjectEx($Context.TargetObject.AdsPath , $True)
foreach ($item in $propertyMap.GetEnumerator())
{
$user.Put($item.Key, $item.Value)
}
# Save changes
try
{
$user.SetInfo()
}
catch
{
$Context.LogMessage("An error occurred when updating user. Error: " + $_.Exception.Message, "Warning")
}
Comments 0
You must be signed in to comment.