Hello Boris,
Thank you for specifying. As such, the scheduled task should look like the following:
You can find the script below. In the script, the $propertyName variable specifies the name of the property to process. It should be the same one as in the condition.
$propertyName = "mobile" # TODO: modify me
# Get property value as is
$propertyValue = $Context.TargetObject.Get($propertyName)
$propertyValue = $propertyValue.Replace("+","").Replace(" ","").Replace(".","")
if (($propertyValue.Length -eq 10) -and ($propertyValue -like "0*"))
{
$propertyValue = $propertyValue.Remove(0,1)
}
if ($propertyValue.Length -eq 9)
{
$propertyValue = "49" + $propertyValue
}
if ($propertyValue.Length -ne 11)
{
$Context.LogMessage("The value $propertyValue of property $propertyName cannot be formatted as its length does not meet the requirements.", "Warning")
return
}
# Format property value
$formattedValue = "+" + $propertyValue.SubString(0,2) + " " + $propertyValue.SubString(2,3) + " " + $propertyValue.SubString(5,3) + " " + $propertyValue.SubString(8,3)
# Update the user
$Context.TargetObject.Put($propertyName, $formattedValue)
$Context.TargetObject.SetInfo()