Replace Accent Characters

i need to replace the characters below in the First Name, Last Name, & username fields before the account is created. for the username i know i can add those characters to the restricted characters list....however this does not replace the characters it just removes the characters from the username. I would like to have the characters replaced with the ASCII equivalents.  what would be the best way to do this? I have attempted to use a workflow but that hasn't worked well so far. If i can't replace the characters i would like to present an error message to the user when they try to add a name with those characters in them. 

ÀàÁáÂâÃãÄäÇçÈèÉéÊêËëÌìÍíÎîÏïÑñÒòÓóÔôÕõÖöŠšÚùÛúÜûÙüÝýŸÿŽž

ASCII mapping below. 

https://docs.oracle.com/cd/E29584_01/webhelp/mdex_basicDev/src/rbdv_chars_mapping.html

  • Here's an article on cleaning accents from strings:

    lazywinadmin.com/.../powershell-remove-diacritics-accents.html

    I setup something to deal with this as follows:

    Create a change workflow to detect a user create.

    Create a script activity that traps and modifies properties you want to fix and place that script active BEFORE the user create in the workflow.

    Sample script activity:

    # Top of script acitivity

    Function RemoveAccents ($AccentedString)

    {

    # Insert cleaning code here

    # Return the clean string

    $CleanedString

    }

    Function CatchAccents ($Request){

    # Catch the accent in the samaccountname

    $NewUserSam = $Request.get("samaccountname")

    $CleanNewUserSam = RemoveAccents $NewUserSam

    # Replace the inbound samaccountname with the cleaned one

    $Request.put("sanaccountname", $CleanNewUserSam)

    $NewUserName = $Request.get("Name")

    $CleanNewUserName = RemoveAccents $NewUserName

    # Replace the inbound user name with the cleaned one

    $Request.put("name", $CleanNewUserName)

    # ...and so on

    } # End of CatchAccents Function

    # End of script activity

  • the $request.put("samaccountname", cleannewusersam) line is failing with the error message below.

    Exception calling "Put" with "2" argument(s): "Object reference not set to an instance of an object."

    i am trying to figure out what the name of the attribute would be in the $request. 

    DEBUG: 20+ >>>> $Request.put("sAMAccountName", $CleanNewUserSam)

    Call method '$Request.Put'
    Arguments list:
    [1] : Value=sAMAccountName : Type=System.String
    [2] : Value=System.Object[] : Type=System.Object[] : IsMultivalued=True : Count=1
    [0] : Value=flastaauyyiinnxyz : Type=System.String
    [1] : Value=

    ERROR:
    At line: 20 char:9. Exception calling "Put" with "2" argument(s): "Object reference not set to an instance of an object."

  • Full Code Below.

    function onPreCreate($Request) {

    function RemoveAccents ($AccentedString){
    [Text.Encoding]::ASCII.GetString([Text.Encoding]::GetEncoding("Cyrillic").GetBytes($accentedString))
    $CleanedString
    }


    $log = "C:\ARS-debug\Log-removeAccents.txt"
    $date = Get-Date
    Add-Content $log $date
    Add-Content $log $request
    $request


    # Catch the accent in the samaccountname
    $NewUserSam = $Request.get("samaccountname")
    $CleanNewUserSam = RemoveAccents $NewUserSam
    # Replace the inbound samaccountname with the cleaned one
    $Request.put("sAMAccountName", $CleanNewUserSam)
    Add-Content $log $cleannewusersam

    # Catch the accent in the Name
    #$NewUserName = $Request.get("Name")
    #$CleanNewUserName = RemoveAccents $NewUserName
    # Replace the inbound user name with the cleaned one
    #$Request.put("name", $CleanNewUserName)
    #Add-Content $log $cleannewusername

    # Catch the accent in the First Name
    $NewFName = $Request.get("givenName")
    $CleanNewFName = RemoveAccents $NewFName
    # Replace the inbound first name with the cleaned one
    $Request.put("givenname", $CleanNewFName)
    Add-Content $log $cleannewfname

    # Catch the accent in the Last Name
    $NewLname = $Request.get("sn")
    $CleanNewLName = RemoveAccents $NewLname
    # Replace the inbound last name with the cleaned one
    $Request.put("sn", $CleanNewLName)
    Add-Content $log $cleannewlname

    # Catch the accent in the Last Name
    $Newmailnickname = $Request.get("mailnickname")
    $CleanNewmailnickName = RemoveAccents $Newmailnickname
    # Replace the inbound last name with the cleaned one
    $Request.put("mailnickname", $CleanNewmailnickName)
    Add-Content $log $cleannewmailnickname

    }

  • when i run the line below it removes the accent characters properly. it just seems like when i run the $request.put it fails. 

    [Text.Encoding]::ASCII.GetString([Text.Encoding]::GetEncoding("Cyrillic").GetBytes($accentedString))

  • Change it to this:

    $CleanedString = [Text.Encoding]::ASCII.GetString([Text.Encoding]::GetEncoding("Cyrillic").GetBytes($accentedString))