Careers   |   Events   |   Contact   |   402.238.1399   |

Connect with us on FacebookConnect with us on LinkedInFollow Us on Twitter

Update Active Directory Accounts from a CSV File using PowerShell

Mar 06, 2012

For instances where there is need to update a specific list of user accounts in Active Directory, it may be ideal to use PowerShell to loop through the list and make the changes for each of the users using the Active Directory Administration Module for PowerShell. For the sake of this example, assume there is a CSV file with a column titled sAMAccountName:


If we wanted to update the Company attribute in AD for each of these users, we could use the following PowerShell script to read in the list of users, and use Get-ADUser to get the specific AD account object, and then pass to Set-ADUser to make the actual change:

1 Import-module ActiveDirectory 2 3 $userList= Import-Csv '.\List of Users.csv' 4 5 foreach ($userin$userList){ 6 Get-ADUser -Filter"SamAccountName -eq '$($user.sAMAccountName)'"-SearchBase "DC=subdomain,DC=company,DC=com"-Properties Company |% { Set-ADUser $_-Replace@{Company = 'Deliveron'} } 7 }


If you then wanted to query AD for those users to make sure they updated correctly, you could use the following query using Get-ADUser:

1 foreach ($userin$userList){ 2 Get-ADUser -Filter"SamAccountName -eq '$($user.sAMAccountName)'"-SearchBase "DC=subdomain,DC=company,DC=com"-Properties Company | Select SamAccountName, Name, Company 3 }

Category: PowerShell

We believe in helping our customers create software solutions in a better way.
We do this by having a project delivery process and technology expertise that ensures we are solving the right problem in the right way and driving the most business value.