Had a quick question from a customer about how one can automatically update the phone number and pager of a lot of AD users. The customer was changing switchboard and had to add 1 number in front of the current number. Adding it in the middle of the string is also possible, but slightly more complicated as you have to split the string.
This is possible to do in a few different ways, but I chose the quickest way for me, via Powershell.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
# Verify how it looks like before executing the script. # It's easy to add a Export-CSV at the end of this line to have a backup. Get-ADUser -SearchBase "OU=Test,DC=dreamhouse,DC=local" -Filter * -properties *| select Name, telephoneNumber, Pager # Add a "2" infront of Pager # Add a "8" infront of TelephoneNumber Get-ADUser -SearchBase "OU=Test,DC=dreamhouse,DC=local" -Filter * -properties * | ForEach-Object { Set-ADObject -Identity $_.DistinguishedName -Replace @{Pager="2$($_.Pager)"} Set-ADObject -Identity $_.DistinguishedName -Replace @{telephoneNumber="8$($_.telephoneNumber)"} } # And Verify it went well. Get-ADUser -SearchBase "OU=Test,DC=dreamhouse,DC=local" -Filter * -properties *| select Name, telephoneNumber, Pager |
End Result: