Write script to update extensionAttribute2 field multiple users

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!
npc_caseymAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Tej Pratap Shukla ~DexterServer AdministratorCommented:
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 : http://richardspowershellblog.wordpress.com/2012/12/09/bulk-modifications-using-set-aduser/
Learn more about Set-ADuser command usage and terminology : http://technet.microsoft.com/en-us/library/ee617215.aspx

I hope this resolves your query

Thanks
~Dex
0
SubsunCommented:
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..
Name
UserA
UserB
UserC

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
npc_caseymAuthor Commented:
Thank you for all of the responses.  I'm going to test these solutions out and will report back.  Thanks all!
0
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

npc_caseymAuthor Commented:
This code worked perfectly.  Thank you!!!!
0
npc_caseymAuthor Commented:
@Subsun

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

Thanks,
Casey
0
SubsunCommented:
Yes it is possible.. Please open a new question for additional requests.. :-)
0
npc_caseymAuthor Commented:
OK no problem.  Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.