Hi
Thanks for the clarification. The value's loading was my next guess :) and you are correct, we do reference the UPN to set the SMTP later in the rule.
I have made the changes you've suggested, but unfortunately they don't seem to be working as I'd hoped. In fact running the rules this way, the UPN never gets updated to be correct.
The only action in the pre-user creation rule is to run this powershell script
$propertyName = "department" # TODO: modify me
$upnSuffixMap = @{
"domain1.com" = @("department 1", "first department", "dept uno")
"domain2.com" = @("department 2", "second department", "dept zwei")
} # TODO: modify. Example: $upnSuffixMap = @{"<UPN Suffix>" = @("<Property Value 1>", "<Property Value 2>")}
# Get property value
try
{
$value = $Context.TargetObject.Get($propertyName)
}
catch
{
return # Property is empty
}
# Get UPN Suffix
$upnSuffix = $NULL
foreach ($item in $upnSuffixMap.GetEnumerator())
{
if ($item.Value -notcontains $value)
{
continue
}
$upnSuffix = $item.Key
break
}
if ([System.String]::IsNullOrEmpty($upnSuffix))
{
$Context.LogMessage("UPN suffix is not specified for '$value'. Default UPN suffix will be used.", "Warning")
return
}
# Get UPN
$userPrincipalName = "%userPrincipalName%"
if ([System.String]::IsNullOrEmpty($userPrincipalName))
{
$Context.LogMessage("Cannot assign a UPN suffix because the user logon name is empty", "Warning")
return
}
# Build new UPN
$userPrincipalName = $userPrincipalName.SubString(0, $userPrincipalName.IndexOf("@")) + "@$upnSuffix"
# Save changes
$Context.SetModifiedPropertyValue("userPrincipalName", $userPrincipalName)
Following that the post creation rule runs through, but with the wrong UPN and thus SMTP address.
I can see from the log that the Set UPN has run with no errors and department is a required field in the form which is used to create these users.