The script makes sure that each word in a text property value starts with a capital letter and the rest are lower case. the script can be used in custom commands and scheduled tasks configured for the User object type or in business rules triggering after an operation (e.g. After updating a user).
Parameters:
- $separators - Specifies the characters that are users to separate parts of the property value.
- $propertyName - Specifies the LDAP name of the property to be updated.
PowerShell
$separators = @("'", " ", "-") # TODO: modify me
$propertyName = "givenName" # TODO: modify me
function ToTitleCase ($string)
{
$string = $string.ToLower()
foreach ($separator in $separators)
{
$stringParts = $string.Split($separator)
for ($i = 0; $i -lt $stringParts.Length; $i++)
{
$stringParts[$i] = $stringParts[$i].SubString(0, 1).ToUpper() + $stringParts[$i].SubString(1)
}
$string = [System.String]::Join($separator, $stringParts)
}
return $string
}
# Get property value
try
{
$value = $Context.TargetObject.Get($propertyName)
}
catch
{
return
}
# Update value
$value = ToTitleCase $value
# Set value
$Context.TargetObject.Put($propertyName, $value)
$Context.TargetObject.SetInfo()
$propertyName = @("givenName", "sn") # TODO: modify me
The script is not intended to work with multiple properties. Specifying an array in the $propertyName variable will not work. Do we understand correctly that you need the script to process all the properties you specify in the variable same way as it currently works for a single property?