[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Quest Powershell to change user's displayName

Posted on 2010-03-30
7
Medium Priority
?
1,418 Views
Last Modified: 2013-11-25
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?
0
Comment
Question by:Ryan Weaver
  • 4
  • 3
7 Comments
 
LVL 71

Accepted Solution

by:
Chris Dent earned 500 total points
ID: 29113844
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
 
LVL 71

Expert Comment

by:Chris Dent
ID: 29114404

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
 
LVL 4

Author Comment

by:Ryan Weaver
ID: 29132487
Excellent!

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

Ryan
0
Free tool for managing users' photos in Office 365

Easily upload multiple users’ photos to Office 365. Manage them with an intuitive GUI and use handy built-in cropping and resizing options. Link photos with users based on Azure AD attributes. Free tool!

 
LVL 4

Author Comment

by:Ryan Weaver
ID: 29135124
Would this also work on the -Name of the user object?
0
 
LVL 4

Author Comment

by:Ryan Weaver
ID: 29136813
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
 
LVL 4

Author Comment

by:Ryan Weaver
ID: 29140960
Possibly:


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

Open in new window

0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 29174879

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

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s time for spooky stories and consuming way too much sugar, including the many treats we’ve whipped for you in the world of tech. Check it out!
Even though starting and growing a lucrative business while you’re still in college sounds impossible, it is actually quite conceivable. There are several reasons why this is the perfect time to start a new venture.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question