Trying to remove the Aprostrophe from a name in several different area's, "samAccountName", "userPrincipalName", "mail" using this script run before user creation, but it's not working.
Example, change the name O'Connel, to OConnel.
I run a similar script but it removes spaces and works well.
$properties = @("samAccountName", "userPrincipalName", "mail") # TODO: modify me
foreach ($property in $properties)
{
if ($Context.IsPropertyModified($property))
{
$value = $Context.GetModifiedPropertyValue($property)
if ($value.Contains(" "))
{
# Remove apostrophe
$value = $value.Replace("'", "")
# Update property
$Context.SetModifiedPropertyValue($property, $value)
# Log message
$Context.LogMessage("Spaces have been removed from $property", "Information")
}
}
}