Hi
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))
{
return
}
# 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))
{
break
}
}
$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)