I use the script I posted in the first question to create the user, if there is no duplicate sam name then the upn is automatically set to samAccountName@MYDOMAIN
Example of user who was created through automated CSV.
Next So I did what was asked with a business rule to run before creating a user and now the SAM name is fixed and working however the UPN didn't set
$htable = @{FirstName="%firstname%";LastName="%lastname%";initials="%initials%";}
if ($Context.IsPropertyModified("samAccountName"))
{
Get property value
$newValue = $Context.GetModifiedPropertyValue("samAccountName")
# Modify the value
$newValue = $newValue + "2"
# Update the value
$Context.SetModifiedPropertyValue("samAccountName", $newValue)
$context.SetModifiedPropertyValue("userPrincipalname", $newValue)
}
So the user would be built but the UPN would not be set.
Example