0 votes


We try to achieve a script where Adaxes replaces all umlauts in the username and mail adress and also checks for duplicate usernames.

What we have so far is from questions on other topic, but we are unable to get it to work. The username and email still come with umlauts. We will not even get the log lines. Can you help us with the script?

Thanks in advance, Mario

Import-Module Adaxes

# Get the username
$username = $Context.GetModifiedPropertyValue("samAccountName")

function ReplaceCharacters($value)
    $map =@{ "å"="a"; "ö"="oe"; "ä"="ae";"ü"="ue"; "ñ"="n"; "é"="e"; " "=""; "'"="" } # TODO: modify me

    foreach ($key in $map.Keys)
        $value = $value.Replace($key, $map[$key])

    return $value
$username = ReplaceCharacters($username)

function IsUserNameUnique($username)
   $user = Get-AdmUser $username -erroraction silentlycontinue
   return $user -eq $Null

# Check if it is unique
if (IsUserNameUnique($username))

# If the username is not unique, add a digit to it
$uniqueUsername = $Null
for ($i = 1; $True; $i++)
    $uniqueUsername = $username + $i
    $uniqueUPNName = $username + $i
    if (IsUserNameUnique($uniqueUsername))

$uniqueUPNName = ReplaceCharacters $uniqueUPNName
$Context.LogMessage("The username is " + $username + "", "Information")
$Context.LogMessage("The UPN is " + $uniqueUPNName + "", "Information")

# Update User Logon Name (pre-Windows 2000)
$Context.SetModifiedPropertyValue("samAccountName", $username)

# Update User Logon Name
$upnSuffix = $Context.GetObjectDomain("%distinguishedName%")
$userLogonName = "$uniqueUPNName" + "@" + $upnSuffix
$Context.SetModifiedPropertyValue("userPrincipalName", $userLogonName)
$Context.SetModifiedPropertyValue("Description", $i)

$Context.LogMessage("The username has been changed to " + $userLogonName + ".", "Information")

$email = $Context.GetModifiedPropertyValue("mail")
$email = ReplaceCharacters $email
Context.SetModifiedPropertyValue("mailNickname", $username)
$Context.SetModifiedPropertyValue("mail", $email)
by (1.1k points)


Can you help us with the script?

How exactly do you execute the script? Is it via a Business Rule triggering Before creating a user? Could you, please, post here or send us (support[at]adaxes.com) a screenshot of the rule? Did you make sure that the script actually gets executed?

We will not even get the log lines.

What exactly do you mean? What logs did you check?

Please log in or register to answer this question.

Related questions

0 votes
1 answer

I have modified the "Rename the user if the Full Name is not unique within the OU" and the "Automatically add a digit to the username if it is not unique" script into one ... .LogMessage("The DN has been changed to " + $modifiedDN ` + ".", "Information")

asked Jul 31, 2013 by jheisley (3.7k points)
0 votes
1 answer

Hello, I hope someone can help me with a specific script. I have tried to put 2 or 3 together that I have found on here but not having much luck. I am looking to have a ... -upn, but it doesn't seesm to be quite what I'm after. Any help would be appreciated.

asked May 20 by adantona (450 points)
0 votes
1 answer

Good Morning, I'm trying to think of a way to set the username of some of our users who have multiple first and last names. For example, Juan Carlos De Vega. The first ... very first name and last 7 of the very last name? Any help would be appreciated! Thanks

asked Dec 28, 2017 by jhair (2.6k points)
0 votes
1 answer

We have multiple secondary domains that are being managed by Adaxes. Everything seems to be working except self service portal login. We tested with our other secondary domains and those ... other than sign failed. What else can I look at to figure this out?

asked Aug 21 by mark.it.admin (5k points)
0 votes
0 answers

We have a process to create unique usernames but it doesn't account for hyphens. We would like to remove the hyphens and continue to use first initial plus the first seven characters from the ... ($UNLT - 1), $UN.Length)) $UNName + ([int]$UNNum + 1) } } }

asked Dec 11, 2015 by tcarp (250 points)
2,352 questions
2,107 answers
132,661 users