So you want to create the username based on the name of the person. Well if the person is of nordic decent he/she might have funny characters that might brake your scripts. So how do we guarantee that you only get a-z?
For fun we will be calling our new user Räksmörgås, why is that? Well it is a swedish word containing all of our special characters. And I do like shrimp sandwish.
First we start with the really lazy approach:
PS C:\> 'Räksmörgås' -replace "([^a-zz0-9])",""
Rksmrgs
Well that doesn’t really make me happy. I can’t visualize the word using what I got so I need to pick it up a notch.
PS C:\> ('Räksmörgås').Normalize([Text.NormalizationForm]::FormD) -replace "([^a-z0-9])",""
Raksmorgas
Now we are close so I really like an all small character username. So
PS C:\> ('Räksmörgås').ToLowerInvariant().Normalize([Text.NormalizationForm]::FormD) -replace "([^a-z0-9])",""
raksmorgas
So what characters are changed when using the Normalize way?
À | A |
---|---|
Á | A |
 | A |
à | A |
Ä | A |
Å | A |
Ç | C |
È | E |
É | E |
Ê | E |
Ë | E |
Ì | I |
Í | I |
Î | I |
Ï | I |
Ñ | N |
Ò | O |
Ó | O |
Ô | O |
Õ | O |
Ö | O |
Ù | U |
Ú | U |
Û | U |
Ü | U |
Ý | Y |
à | a |
á | a |
â | a |
ã | a |
ä | a |
å | a |
ç | c |
è | e |
é | e |
ê | e |
ë | e |
ì | i |
í | i |
î | i |
ï | i |
ñ | n |
ò | o |
ó | o |
ô | o |
õ | o |
ö | o |
ù | u |
ú | u |
û | u |
ü | u |
ý | y |