- Jun 13, 2000
- 26,389
- 1,778
- 126
Powershell...
I'm trying to properly format names to add them to Active Directory and a few other systems. Basically, the data I'm getting isn't very clean. I've found some random characters in the past where people have entered parenthesis and apostrophes...of course, I see latin-1 characters too. This is all UTF8, but it catches a lot of junk.
I'm curious if anyone knows of any standard processes to throw these names through to get them all somewhat consistent on the other side. Right now, I'm just taking the fields and making them a little more friendly with a replace command
For example adding a second apostrophe to allow them (they are valid in AD, but must be escaped) and then removing parenthesis:
$FIRST = ($FIRSTNAME -replace "'","''" -replace "\(","" -replace "\)","")
Then, I make sure the first letter is set to TitleCase:
$FIRST = (Get-Culture).TextInfo.ToTitleCase($FIRST)
These two steps handle most of the situations I can think of...someone entered as all caps, or all lowercase....it allows names like O'Malley through, but changes them to O'malley.
Names like Mckay or MacGruber would be Mckay/Macgruber. Anyone know of a good reference to build in the logic to fix those without negatively impacting people with NORMAL names? Sorry...gotta make fun since I'm of Scottish and Irish decent.
I'm trying to properly format names to add them to Active Directory and a few other systems. Basically, the data I'm getting isn't very clean. I've found some random characters in the past where people have entered parenthesis and apostrophes...of course, I see latin-1 characters too. This is all UTF8, but it catches a lot of junk.
I'm curious if anyone knows of any standard processes to throw these names through to get them all somewhat consistent on the other side. Right now, I'm just taking the fields and making them a little more friendly with a replace command
For example adding a second apostrophe to allow them (they are valid in AD, but must be escaped) and then removing parenthesis:
$FIRST = ($FIRSTNAME -replace "'","''" -replace "\(","" -replace "\)","")
Then, I make sure the first letter is set to TitleCase:
$FIRST = (Get-Culture).TextInfo.ToTitleCase($FIRST)
These two steps handle most of the situations I can think of...someone entered as all caps, or all lowercase....it allows names like O'Malley through, but changes them to O'malley.
Names like Mckay or MacGruber would be Mckay/Macgruber. Anyone know of a good reference to build in the logic to fix those without negatively impacting people with NORMAL names? Sorry...gotta make fun since I'm of Scottish and Irish decent.