Answered by:
How do i BULK Modify the Phone and Mobile phone attributse using a .CSV file in 2008 server AD
Question
-
Answers
-
I believe, the attributes you want are telephoneNumber ("Telephone Number" displayed on the "General" tab ADUC) and mobile (on the "Telephones" tab of ADUC). You can use Get-ADUser to create the csv, and Set-ADUser to update users from the modifed csv. You should export distinguishedName with the others, to uniquely identify the user objects. To export (this is one line, so watch for line wrapping):
Get-ADUser -Filter * -Properties distinguishedName, telephoneNumber, mobile | Select distinguishedName, telephoneNumber, mobile | Export-Csv -Path c:\scripts\Phone.csv
-----
After you modify the csv file (perhaps delete lines for users that do not need modification), you can import using this (again one line):
Import-Csv -Path c:\Scripts\Phone.csv | ForEach {Set-ADUser $_.distinguishedName -mobilePhone $_.mobile -OfficePhone $_.telephoneNumber}
-----
This assumes you have the AD modules, Get-ADUser and Set-ADUser. If not, reply. Also, let us know if you need to update other telephone attributes, as there are many. They are documented here:
Richard Mueller - MVP Directory Services
- Proposed as answer by Bigteddy Friday, October 19, 2012 3:51 PM
- Marked as answer by Worried_man Friday, October 19, 2012 5:21 PM
-
Get-ADUser -searchbase 'ou=users,ou=london,dc=dontknow,dc=com' -Filter * -Properties distinguishedName, telephoneNumber, mobile |
Select distinguishedName, telephoneNumber, mobile | Export-Csv -Path c:\scripts\Phone.csv
Grant Ward, a.k.a. Bigteddy
- Edited by Bigteddy Friday, October 19, 2012 4:38 PM
- Marked as answer by Worried_man Friday, October 19, 2012 5:21 PM
-
Is it possible you don't have permissions to update the user phone numbers in the OU? Can you modify these attributes in ADUC?
A more likely explanation. You need to use "Run as administrator". When I start a PowerShell session, I right click my shortcut to PowerShell and select "Run as administrator". I also have this option on my Start menu. Without this, your administrator credentials are not used.
Richard Mueller - MVP Directory Services
- Edited by Richard MuellerMVP, Moderator Friday, October 19, 2012 5:00 PM Added last paragraph
- Marked as answer by Worried_man Friday, October 19, 2012 5:21 PM
All replies
-
-
-
I believe, the attributes you want are telephoneNumber ("Telephone Number" displayed on the "General" tab ADUC) and mobile (on the "Telephones" tab of ADUC). You can use Get-ADUser to create the csv, and Set-ADUser to update users from the modifed csv. You should export distinguishedName with the others, to uniquely identify the user objects. To export (this is one line, so watch for line wrapping):
Get-ADUser -Filter * -Properties distinguishedName, telephoneNumber, mobile | Select distinguishedName, telephoneNumber, mobile | Export-Csv -Path c:\scripts\Phone.csv
-----
After you modify the csv file (perhaps delete lines for users that do not need modification), you can import using this (again one line):
Import-Csv -Path c:\Scripts\Phone.csv | ForEach {Set-ADUser $_.distinguishedName -mobilePhone $_.mobile -OfficePhone $_.telephoneNumber}
-----
This assumes you have the AD modules, Get-ADUser and Set-ADUser. If not, reply. Also, let us know if you need to update other telephone attributes, as there are many. They are documented here:
Richard Mueller - MVP Directory Services
- Proposed as answer by Bigteddy Friday, October 19, 2012 3:51 PM
- Marked as answer by Worried_man Friday, October 19, 2012 5:21 PM
-
-
-
-
-
-
Sorry, i am new at this so do i add the search base right before the -filter switch? like this ?
Get-ADUser -searhbase user.london.dontknow.com -Filter * -Properties distinguishedName, telephoneNumber, mobile | Select distinguishedName, telephoneNumber, mobile | Export-Csv -Path c:\scripts\Phone.csv
-
Get-ADUser -searchbase 'ou=users,ou=london,dc=dontknow,dc=com' -Filter * -Properties distinguishedName, telephoneNumber, mobile |
Select distinguishedName, telephoneNumber, mobile | Export-Csv -Path c:\scripts\Phone.csv
Grant Ward, a.k.a. Bigteddy
- Edited by Bigteddy Friday, October 19, 2012 4:38 PM
- Marked as answer by Worried_man Friday, October 19, 2012 5:21 PM
-
Thanks people, Big teddy and Richard. But i am getting this access denied error message when i try to run the set-aduser command. Any reason why? I just copied and pasted it from here so not sure if anything went wrong there. I appreciate your help.
Set-ADUser : Insufficient access rights to perform the operation
At line:1 char:60
+ Import-Csv -Path c:\Scripts\Phone.csv | ForEach {Set-ADUser <<<< $_.distinguishedName -mobilePhone $_.mobile -Office
Phone $_.telephoneNumber}
+ CategoryInfo : NotSpecified: (CN=worried...ramlasplash,DC=ca:ADUser) [Set-ADUser], ADException
+ FullyQualifiedErrorId : Insufficient access rights to perform the operation,Microsoft.ActiveDirectory.Management
.Commands.SetADUser -
Is it possible you don't have permissions to update the user phone numbers in the OU? Can you modify these attributes in ADUC?
A more likely explanation. You need to use "Run as administrator". When I start a PowerShell session, I right click my shortcut to PowerShell and select "Run as administrator". I also have this option on my Start menu. Without this, your administrator credentials are not used.
Richard Mueller - MVP Directory Services
- Edited by Richard MuellerMVP, Moderator Friday, October 19, 2012 5:00 PM Added last paragraph
- Marked as answer by Worried_man Friday, October 19, 2012 5:21 PM
-
-
-