PowerShell: overwriting a AD user property with another property

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)}

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>