[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Write script to update extensionAttribute2 field multiple users

Posted on 2014-08-08
7
Medium Priority
?
961 Views
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!
0
Comment
Question by:npc_caseym
  • 4
  • 2
7 Comments
 
LVL 12

Expert Comment

by:Tej Pratap Shukla ~Dexter
ID: 40248432
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
 
LVL 40

Accepted Solution

by:
Subsun earned 2000 total points
ID: 40248479
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
 

Author Comment

by:npc_caseym
ID: 40249013
Thank you for all of the responses.  I'm going to test these solutions out and will report back.  Thanks all!
0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

 

Author Closing Comment

by:npc_caseym
ID: 40249040
This code worked perfectly.  Thank you!!!!
0
 

Author Comment

by:npc_caseym
ID: 40255345
@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
 
LVL 40

Expert Comment

by:Subsun
ID: 40255423
Yes it is possible.. Please open a new question for additional requests.. :-)
0
 

Author Comment

by:npc_caseym
ID: 40255919
OK no problem.  Thanks.
0

Featured Post

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here's a look at newsworthy articles and community happenings during the last month.
Microsoft Office 365 is a subscriptions based service which includes services like Exchange Online and Skype for business Online. These services integrate with Microsoft's online version of Active Directory called Azure Active Directory.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Loops Section Overview

829 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