We're Hiring!
Take the next step in your career and work on diverse technology projects with cross-functional teams.
LEARN MORE
Mountain West Farm Bureau Insurance
office workers empowered by business technology solutions
BLOG
3
6
2012

Update Active Directory Accounts from a CSV File using PowerShell

Last updated:
8.16.2021

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.

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:

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

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:

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

Recent Blog Posts

lunavi logo alternate white and yellow
9.9.2024
09
.
09
.
2024
Exploring Microsoft Fabric: A Comprehensive Overview

Discover how Microsoft Fabric transforms data management and analytics with powerful tools for real-time insights and seamless collaboration, driving smarter, faster business decisions.

Learn more
lunavi logo alternate white and yellow
9.5.2024
08
.
29
.
2024
Unlock the Future with Data & AI: Why Partnering with Lunavi Makes All the Difference

Learn about the Microsoft Data and AI designation, how Lunavi earned the designation and the power of Data and AI

Learn more
lunavi logo alternate white and yellow
8.7.2024
07
.
31
.
2024
Disaster-Proof Your Business: Automate Recovery with Azure Traffic Manager

Discover how automating disaster recovery with Azure Traffic Manager can significantly enhance your business's resilience and ensure uninterrupted operations during unforeseen events.

Learn more