PowerShell script to copy mobile phone number to telephone number in AD
Summary
This TechNet Wiki is based on the TechNet Forum Post - PowerShell Script to copy mobile phone number to telephone number
Requirement
OP requested for a PowerShell script which updates Telephone Number with Mobile Number.
Code Used
Get-QADGroup "test1"| ForEach-Object{ Get-QADGroupMember$_.samaccountname}| select samaccountname,mobilephone | export-csvD:\test1.csv Import-Csv "D:\test1.csv"| %{Get-QADUSer$_.Samaccountname | Set-QADUser-ObjectAttributes@{telephonenumber=$_.mobilephone}} |
Challenges
- While exporting the attribute, we are not getting the proper telephone format in CSV which is "+919999XXX1111"
- If telephone number attribute of a user is already filled, it does not update the attribute. It only updates the attribute if it is blank.
Solution
Import-Module ActiveDirectory Import-Csv "D:\test1.csv" | %{Set-ADUser -Identity $_.samaccountname -OfficePhone $_.mobilephone} |
Help
help Import-Module -Detailed help Import-Csv -Detailed help Set-ADUser -Detailed help foreach -Detailed help ForEach-Object -Detailed |