PowerShell: overwriting a AD user property with another property

31 May 2010

I have some users in AD, which had a wrong Telephone property specified.
The value was correct specified in the Mobile Phone property, so I wanted to copy this value from every user into the Telephone property.

A picture says more than a 1000 words.

A picture says more than a 1000 words.

Off course, PowerShell comes to mind.
First I tried it with the standard AD commands get-aduser en set-aduser.

Get-ADuser will give you the Telephone property and mobilephone property, but set-aduser will not let you update the telephone property, it only support 47 properties and Telephone isn’t one of them.

Next stop: Quests PowerShell AD commands.
You can use get-qaduser and set-qaduser.

So I tried the command:

get-qaduser –SearchRoot ‘Domain/OU/OU’ | set-qaduser – PhoneNumber $_.mobilePhone

This gave me an empty PhoneNumber property in AD.
After trying a lot and searching the internet, I stumbled upon this forum post, who else than Shay Levy would give me the answer.

get-qaduser -SearchRoot ‘Domain/OU/OU’ | % {set-qaduser $_ -telephonenumber $($_.MobilePhone)}

Share This:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • PDF
  • Twitter

Comment Form