none
How do i BULK Modify the Phone and Mobile phone attributse using a .CSV file in 2008 server AD RRS feed

  • Question

  • Hi I want to Modify the Phone and MobilePhone Attributes for members in a specific OU in our AD.  We are using 2008 server.  I would like to use Powershell to achieve this.  Please help.
    Friday, October 19, 2012 2:53 PM

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:

    http://social.technet.microsoft.com/wiki/contents/articles/6822.active-directory-attributes-in-the-aduc-gui-tool-en-us.aspx


    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
    Friday, October 19, 2012 3:28 PM
    Moderator
  • 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
    Friday, October 19, 2012 4:35 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


    Friday, October 19, 2012 4:56 PM
    Moderator

All replies

  • I assume you don't have the AD module, so I would recommend installing the Quest AD cmdlets.  This makes it easy to work with properties of AD objects.

    Grant Ward, a.k.a. Bigteddy

    Friday, October 19, 2012 2:56 PM
  • I do have an AD module.  But what i want to do is Export the user information to a .csv file for the members i want to Modify and then take that .csv file and use it to change the Mobilephone and the phone attributes of the users using Powershell.
    Friday, October 19, 2012 3:07 PM
  • 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:

    http://social.technet.microsoft.com/wiki/contents/articles/6822.active-directory-attributes-in-the-aduc-gui-tool-en-us.aspx


    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
    Friday, October 19, 2012 3:28 PM
    Moderator
  • I will try this and let you know how i did shortly. 
    Friday, October 19, 2012 3:48 PM
  • It is telling me that 'Get-Aduser is not recognized as the name of a cmdlet. 
    Friday, October 19, 2012 3:51 PM
  • You must run:

    Import-Module ActiveDirectory

    first.


    Grant Ward, a.k.a. Bigteddy

    Friday, October 19, 2012 3:56 PM
  • Is there a way to narrow down the output of the CSV file export to just one specific OU?
    Friday, October 19, 2012 4:04 PM
  • Add -Searchbase to Get-AdUser.  This takes a parameter in the form of a FQDN.  You can also add -Seachscope to "Base", "Onelevel", or "Subtree".  The default is "Subtree".

    Grant Ward, a.k.a. Bigteddy


    • Edited by Bigteddy Friday, October 19, 2012 4:07 PM
    Friday, October 19, 2012 4:06 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

    Friday, October 19, 2012 4:26 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
    Friday, October 19, 2012 4:35 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

    Friday, October 19, 2012 4:53 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


    Friday, October 19, 2012 4:56 PM
    Moderator
  • Thanks that worked like a charm.

    Thanks to both of you.

    Friday, October 19, 2012 5:21 PM
  • Hello, i know that it has been a while.  Is there a way to acheive this for a number of Users from different OU's?  using their aliases or Fist name last name?
    Thursday, November 29, 2012 7:26 PM
  • Thank you very much , Command is really helpful
    Tuesday, May 15, 2018 12:27 PM