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 (530 points)
edited by

1 Answer

0 votes
by (288k 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
1 answer

Hi all, I have a condition during new user creation - Where the corporate email is entered into the email address field, but a custom drop-down for "Mailbox required?" is No. ... screen, and be able to save the result of this choice to a variable? Thanks all,

asked Oct 24 by dshortall (80 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 (190 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)
3,538 questions
3,229 answers
8,224 comments
547,747 users