0 votes

I've tried the following script to adapt the UPN to the country, the step will be processed in "before user creation" but the UPN stays default to com:


$propertyName = "countryCode" 
$upnSuffixMap = @{
    "companyName.com" = @("276")
    "companyName.in" = @("356")
    "companyName.cn" = @("156")
    "companyName.com.tr" = @("792")
} 

# 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 was not specified for '$value'. companyName.com 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.TargetObject.Put("userPrincipalName", $userPrincipalName)
$Context.TargetObject.SetInfo()
related to an answer for: UPN name is associated with country,
by (450 points)
edited by

1 Answer

0 votes
by (270k points)

Hello Boris,

The script will not work as the Set-ADUser cmdlet can only be used with existing users. For information on how to achieve the desired, have a look at the following tutorial: https://www.adaxes.com/tutorials_SimplifyingDataEntry_ValidateModifyUserInputWithScript.htm.

0

OK thanks, I will have a look on it

Related questions

0 votes
1 answer

Dear Support We have a business rule in the old Adaxes 2017 that was working: Before adding a universal security group to a global security group, the group type of the ... adding a universal group to a global group? <br> Our action: Best regards Johann

asked Nov 30, 2021 by Johann Ihnen (170 points)
0 votes
0 answers

When the UPN being created is the same as an existing one except for the case. For instance, the new UPN is sally.fields but there's an existing Sally.Fields. The ... but then fails to create the AD account indicating that the UPN is not unique forestwide.

asked Jul 13, 2022 by sandramnc (870 points)
0 votes
1 answer

At user creation, when the inbox is created, I'd like to be able to format the address as firstname.lastname@domain.com for some users. Other users firstnameintial.lastname@domain.com, is this possible? Envornment is hybrid O365. Thanks!

asked Jan 4 by cewilson (120 points)
0 votes
1 answer

Hi, I want to change the default UPN suffix for user creation. We only have a single UPN suffix we use at our organization however when we create a user using the web ... We only ever want to use the @mycompany.com so a list of options isn't requried.

asked Jun 29, 2022 by PeterG (40 points)
0 votes
0 answers

We are in hybrid mode with 365. All the accounts we create have to made with a .com instead of .local. How can I make that change in adaxes? Or is this some default I need to change in AD instead?

asked Apr 11, 2022 by LEGIT1 (150 points)
3,326 questions
3,026 answers
7,727 comments
544,678 users