0 votes

I would like to replace some characters "before user creation". With character like umlaute "ä", "ö", "ü". The script works. But characters like "é", "ô" doesn't seem to be replaced.

Im using this script:

$props = @("sAMAccountName", "userPrincipalName", "mail")
$map =@{ " " ="";"Á"="A";"Ă"="A";"Â"="A";"Å"="A";"Ä"="Ae";"Ǟ"="Ae";"Ã"="A";"Ą"="A";"Ā"="A";"Ć"="C";"Ĉ"="C";"Ċ"="C";"Ç"="C";"Ď"="D";"Ḑ"="D";"Đ"="D";"Ð"="D";"É"="E";"Ê"="E";"Ě"="E";"Ë"="E";"Ė"="E";"Ę"="E";"Ē"="E";"Ğ"="G";"Ĝ"="G";"Ġ"="G";"Ģ"="G";"Ĥ"="H";"ħ"="h";"İ"="I";"ı"="i";"Í"="I";"Ì"="I";"Î"="I";"Ï"="I";"Ĩ"="I";"Ī"="I";"Ĵ"="J";"Ķ"="K";"Ĺ"="L";"Ļ"="L";"Ł"="L";"Ŀ"="L";"Ń"="N";"Ň"="N";"Ñ"="N";"Ņ"="N";"Ŋ"="N";"Ó"="O";"Ò"="O";"Ô"="O";"ö"="oe";"Ȫ"="Oe";"Ő"="Oe";"Õ"="O";"Ȯ"="O";"Ø"="O";"Ř"="R";"Ŕ"="R";"Ŗ"="R";"Ś"="S";"Ŝ"="S";"Š"="S";"Ş"="S";"Ṣ"="S";"Ș"="S";"ß"="ß";"Ť"="T";"Ţ"="T";"Ț"="T";"Ŧ"="T";"Ú"="U";"Ù"="U";"Ŭ"="U";"Û"="U";"Ů"="U";"Ü"="Ue";"Ű"="Ue";"Ŵ"="W";"Ý"="Y";"Ŷ"="Y";"Ÿ"="Y";"Ȳ"="Y";"Ź"="Z";"Ž"="Z";"Ż"="Z";}

foreach ($prop in $props)
{
    if ($Context.IsPropertyModified($prop))
    {
        $value = $Context.GetModifiedPropertyValue($prop)

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

        $Context.SetModifiedPropertyValue($prop, $value)
        $Context.LogMessage($prop + ": " + $value, "Information")
    }
}

If i add lower and upper case i get an error message: "Duplicate keys are not allow in hash literals"

I know some characters are automatically interpreted as normal characters from AD, but with the mail address and upn we have some issues with it in the Azure World. Do you have a solution for this?

by (50 points)

1 Answer

+1 vote
by (288k points)

Hello,

The behavior is expected. First of all, the replace method is case-sensitive. As a result, if lowercase characters are present in a property value, but not present in the mapping, they will not be replaced. At the same time, it is not possible to specify a mapping in a single hash table for both lowercase and uppercase characters as the tables do not allow such a thing. Both points come from PowerShell itself and are not related to Adaxes. To achieve the desired, you need to have two mappings. One for uppercase characters and one for lowercase characters. Finally, you should have something like the following:

$props = @("sAMAccountName", "userPrincipalName", "mail")
$mapUppercase =@{" " ="";"Á"="A";"Ă"="A";"Â"="A";"Å"="A";"Ä"="Ae";"Ǟ"="Ae";"Ã"="A";"Ą"="A";"Ā"="A";"Ć"="C";"Ĉ"="C";"Ċ"="C";"Ç"="C";"Ď"="D";"Ḑ"="D";"Đ"="D";"Ð"="D";"É"="E";"Ê"="E";"Ě"="E";"Ë"="E";"Ė"="E";"Ę"="E";"Ē"="E";"Ğ"="G";"Ĝ"="G";"Ġ"="G";"Ģ"="G";"Ĥ"="H";"ħ"="h";"İ"="I";"ı"="i";"Í"="I";"Ì"="I";"Î"="I";"Ï"="I";"Ĩ"="I";"Ī"="I";"Ĵ"="J";"Ķ"="K";"Ĺ"="L";"Ļ"="L";"Ł"="L";"Ŀ"="L";"Ń"="N";"Ň"="N";"Ñ"="N";"Ņ"="N";"Ŋ"="N";"Ó"="O";"Ò"="O";"Ô"="O";"ö"="oe";"Ȫ"="Oe";"Ő"="Oe";"Õ"="O";"Ȯ"="O";"Ø"="O";"Ř"="R";"Ŕ"="R";"Ŗ"="R";"Ś"="S";"Ŝ"="S";"Š"="S";"Ş"="S";"Ṣ"="S";"Ș"="S";"ß"="ß";"Ť"="T";"Ţ"="T";"Ț"="T";"Ŧ"="T";"Ú"="U";"Ù"="U";"Ŭ"="U";"Û"="U";"Ů"="U";"Ü"="Ue";"Ű"="Ue";"Ŵ"="W";"Ý"="Y";"Ŷ"="Y";"Ÿ"="Y";"Ȳ"="Y";"Ź"="Z";"Ž"="Z";"Ż"="Z";}
$mapLowercase =@{"ä"="a";"ö"="o";"ü"="u";"é"="e";"ô"="o"} # TODO: modify me

foreach ($prop in $props)
{
    if ($Context.IsPropertyModified($prop))
    {
        $value = $Context.GetModifiedPropertyValue($prop)

        foreach ($key in $mapUppercase.Keys)
        {
            $value = $value.Replace($key, $mapUppercase[$key])
        }

        foreach ($key in $mapLowercase.Keys)
        {
            $value = $value.Replace($key, $mapLowercase[$key])
        }

        $Context.SetModifiedPropertyValue($prop, $value)
        $Context.LogMessage($prop + ": " + $value, "Information")
    }
}

Related questions

0 votes
1 answer

This is more a general question to the community not a support request - What tools or products have you integrated into your Adaxes workflows? One example that I did was ... calling a custom command to pass user properties to Adaxes. What are your ideas? :)

asked Apr 4, 2023 by GronTron (320 points)
0 votes
1 answer

We want to automate the provisioning of skype users with adaxes. Therefore we installed the Skype module onto the adaxer server. Then we tried to utilise some commands in a ... . How can the Skype module be integrated for Adaxes? Thank you for your help.

asked Apr 23, 2020 by PGstoehl (100 points)
0 votes
1 answer

Hi , I would like to know that is there any API service, where we can work on objects inside Adaxes tool? Preferbly REST API?

asked Nov 6, 2019 by Anil (20 points)
0 votes
1 answer

I want to remove special characters on the onboarding web form for username and mail before clicking Finish. Using a script like on the rule "Before User Creation" seems to to do the change to late and you can not verify the email adress before created.

asked Dec 27, 2021 by joem (20 points)
0 votes
1 answer

When creating business rules I quite often find myself having to create overly complex workflows because we can't use ELSE or BREAK statements. An example would be:- ... am I missing something in how to construct business rules that mimics their use? Thanks

asked Sep 23, 2014 by firegoblin (1.6k points)
3,542 questions
3,233 answers
8,227 comments
547,809 users