Write script to update extensionAttribute2 field multiple users

Posted on 2014-08-08
Last Modified: 2014-08-12
I need to write a script that will pull in a CSV list of AD users and update the extensionAttribute2 field for said users.  I know the basics and I'll need to use the set-aduser command but I'm not sure exactly how to do the rest.  Please help!
Question by:npc_caseym
    LVL 11

    Expert Comment

    by:Tej Pratap Shukla ~Dexter
    Hey there,
    The procedure is quite simple:
     First, you need to import the csv into a variable , here we took "usercsv"   .
    Second, we will provide filters as required and update fields respectively using Get and Set attribute commands :
    Consider this example for deeper understanding -
    #$userscsv = import-csv D:\home\test.csv            
    $users = Import-Csv -Path D:\Scripts\test.csv            

    foreach ($user in $users) {            
    #Search in specified OU and Update existing attributes            
     Get-ADUser -Filter "SamAccountName -eq '$($user.samaccountname)'" -Properties * -SearchBase "cn=Users,DC=manticore,DC=org" |            
      Set-ADUser -City $($user.City) -Office $($user.Office) -Division $($user.Division)            

    Courtsey :
    Learn more about Set-ADuser command usage and terminology :

    I hope this resolves your query

    LVL 40

    Accepted Solution

    Following code will do it..
    Import-Csv C:\USER.CSV | %{
    Set-ADUser -Identity $_.Name -replace @{extensionAttribute2="myValue"}

    Open in new window

    USER.CSV sample shown below..

    Open in new window


    Author Comment

    Thank you for all of the responses.  I'm going to test these solutions out and will report back.  Thanks all!

    Author Closing Comment

    This code worked perfectly.  Thank you!!!!

    Author Comment


    The solution you gave me works perfectly.  One additional would I add a field to it?  If I wanted to update the Organization AD field with data in the second column of the that possible?

    LVL 40

    Expert Comment

    Yes it is possible.. Please open a new question for additional requests.. :-)

    Author Comment

    OK no problem.  Thanks.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Hi all.   The other day I had to change the passwords for a bunch of users on the fly. Because they were so many, I decided to do it in an automated way and I would like to share it with you all.   If you are not doing it directly in a Domain Co…
    Synchronize a new Active Directory domain with an existing Office 365 tenant
    This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
    This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now