Quest Powershell to change user's displayName

I accidentally added a good number of users with their displayName containing a '.' between their first and last name (mirrors the sAMAccountName).

I would like to user Quest's Powershell to correct this issue. I can get the list of users from the OU and single out the ones with the '.', but I am at a loss as to how to get that attribute out, strip the '.' and set the new displayName on the user object. I was thinking it could have been a simple pipeline, but it's not working out for me.

Can someone help me with this?
LVL 4
Ryan WeaverInfrastructure ManagerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris DentPowerShell DeveloperCommented:
Hello :)

This should do, although you shouldn't take my word for that, test first :)

It should get all users with a dot in the middle of their display name, then for that user it should replace the dot with a space and apply the change.

HTH

Chris
Get-QADUser -DisplayName "*.*" | %{ 
  Set-QADUser $_.DN -DisplayName $($_.DisplayName -Replace "\.", " ")
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Chris DentPowerShell DeveloperCommented:

I reckon it's worth having a note on -Replace.

-Replace matches what it's to replace using a regular expression. In the Regular expression world "." is a single character, any character. We need the there \ to escape it's meaning so it matches only the dot.

Always nice to see things in action:

Write-Host "Working replacement: '$('bob.hope' -Replace '\.', ' ')'"
Write-Host "Broken replacement: '$('bob.hope' -Replace '.', ' ')'"

The first gives you the name without the period, the second just a block of spaces.

Chris
0
Ryan WeaverInfrastructure ManagerAuthor Commented:
Excellent!

And thank you for the note on -Replace as I probably would have made that mistake :)

Ryan
0
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

Ryan WeaverInfrastructure ManagerAuthor Commented:
Would this also work on the -Name of the user object?
0
Ryan WeaverInfrastructure ManagerAuthor Commented:
After reading through Set-QADUser, I'm guessing not... Would it be 'moved' instead to a new CN to make the change on the 'Name' happen?
0
Ryan WeaverInfrastructure ManagerAuthor Commented:
Possibly:


Get-QADUser -SearchRoot "<DN>" -Name "*.*" | %{Rename-QADObject $_.DN -NewName $($_.Name -Replace "\.", " ") -WhatIf }

Open in new window

0
Chris DentPowerShell DeveloperCommented:

DisplayName and Name are quite different. Name is the one you see in AD Users and Computers. Is that the one you'd like to change? Your code for that looks pretty good though :)

Chris
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Project Management

From novice to tech pro — start learning today.