Friday, August 9, 2013

ActiveDirectory - Update User Info From CSV

 We will update the Department of our users using PowerShell:

1. Create a CSV file contains sAMAccountName column and all needed information, e.g. C:\userlist.csv:

supergenius,Super Man Department
ironman,The Advanger

2. In AD Controller, open Active Directory Module for Windows PowerShell, and run the following command:

Import-Csv C:\userlist.csv | foreach { Get-ADUser -Identity $($_.sAMAccountName) | Set-ADUser -Department $($_.department) }

Update: the Active Directory Module for Windows PowerShell is only available in Windows Server 2008 R2 and Windows 7.