none
Powershell - Need Help. How can you make AD searches easier for objects containing foreign letters? RRS feed

  • Question

  • Greetings, I have created a script for our local infrastructure to copy a user in AD, generate and create a username and email address, generate personal fileshare and enable email and Lync.
    I work at a global company and have been asked to make sure all our IT admins around the globe is able to use the script.
    I have one problem remaining that I can't figure out.

    When you search for a user on the domain controller in Active Directory Users and Computers, you are able to find a user with the $_.name "Cécile Soulé" (french) by typing "Cecile" in the search box, but a script using Get-AdUser isn't able to do so. There I have to type in "Céline" directly.

    My question is this: Is there a way to get your script to behave like the search in Active Directory Users and Computers in this regard or would it be so complicated that it wouldn't be worth it?

    Characters included in various names: æ, ø, å, á, à, â, ä, ç, é, è, ê, ë, í, î, ï, ó, ô, œ, ú, ü, ù, û, ÿ, ñ.

    This is the search line I use: get-aduser -server $server -credential $credential1 -Filter * -properties name, samaccountname, office |? { $_.name -like "$SearchName*" -or $_.samaccountname -like "$SearchName*"}

    I hope you can help, because after several hours af searching on the net, I haven't gotten closer to an answer. Perhaps because it is hard to define the request specifically.

    Thursday, November 13, 2014 3:24 PM

Answers

  • Thanks for taking the time to answer.

    Unfortunately this is neither a problem with escaping characters or removing accents. I did find a solution however.

    Instead of removing accents, I had to make the characters open to possible accents. I made a script to give me all the names that were using these letters in the AD, and found out that I had been way too hasty when I thought all those letters I posted in #0 were used. I thought I had to take all of them into account since they were in the various countries alphabet, which gave me a huge amount of results on some names. My advice would be to only replace what is needed (though for possible future use, it would be preferable to include all of them somehow)

    I just replaced all the english letters you would type, instead of the foreign letters, with wildcards. In fact it turned out that everything could be covered with just this line: 

    $SearchName = $SearchName -replace "e","?" -replace "i","?" -replace "a","?" -replace "o","?" -replace "ae","?" -replace "n","?" -replace "æ","?"

    This will find names with these letters: æ, ø, å, á, à, â, ä, é, è, ê, ë, í, î, ï, ó, ô, œ, ñ.

    Just thought I would show how I did it, in case anyone else stumbles on this problem.


    • Edited by Pharalax Thursday, November 13, 2014 11:30 PM Added list of letters for clarification.
    • Marked as answer by Pharalax Friday, November 14, 2014 7:13 AM
    Thursday, November 13, 2014 11:23 PM

All replies

  • Maybe this will help:

    http://stackoverflow.com/questions/7836670/how-remove-accents-in-powershell


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

    Thursday, November 13, 2014 3:37 PM
    Moderator
  • You can escape the characters (using the backslash "\" escape character), as long as you know the ASCII hexadecimal representation of the character. The following Wiki article explains:

    http://social.technet.microsoft.com/wiki/contents/articles/5312.active-directory-characters-to-escape.aspx#Non-Keyboard_Characters

    You could script a Replace, to replace any specific characters with the escaped equivalent.


    Richard Mueller - MVP Directory Services



    Thursday, November 13, 2014 3:43 PM
    Moderator
  • Thanks for taking the time to answer.

    Unfortunately this is neither a problem with escaping characters or removing accents. I did find a solution however.

    Instead of removing accents, I had to make the characters open to possible accents. I made a script to give me all the names that were using these letters in the AD, and found out that I had been way too hasty when I thought all those letters I posted in #0 were used. I thought I had to take all of them into account since they were in the various countries alphabet, which gave me a huge amount of results on some names. My advice would be to only replace what is needed (though for possible future use, it would be preferable to include all of them somehow)

    I just replaced all the english letters you would type, instead of the foreign letters, with wildcards. In fact it turned out that everything could be covered with just this line: 

    $SearchName = $SearchName -replace "e","?" -replace "i","?" -replace "a","?" -replace "o","?" -replace "ae","?" -replace "n","?" -replace "æ","?"

    This will find names with these letters: æ, ø, å, á, à, â, ä, é, è, ê, ë, í, î, ï, ó, ô, œ, ñ.

    Just thought I would show how I did it, in case anyone else stumbles on this problem.


    • Edited by Pharalax Thursday, November 13, 2014 11:30 PM Added list of letters for clarification.
    • Marked as answer by Pharalax Friday, November 14, 2014 7:13 AM
    Thursday, November 13, 2014 11:23 PM