Update AD attributes from a csv file

Naveen Kumar 21 Reputation points

I need to update all below mentioned AD attributes from a CSV file, please let me know if i can update these in one script or do i need multiple scripts? Please help me with detailed steps, i am not so good in scripting. Thanks.

CSV file have filled:


Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
6,215 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,455 questions
{count} votes

Accepted answer
  1. Rich Matheisen 45,831 Reputation points

    You could continue adding the individual parameters and values to the Set-ADUser cmdlet, making it longer and more cumbersome to deal with, of you could use a hash to assemble the parameters and values and use "splatting" to keep the clutter down.

    I also added some minimal error handling.

    Import-Csv -Path "C:\temp\adinfo.csv" | 
        ForEach-Object {
            # properties from the csv
            $acct = $_.samaccountname     # needed for error message
            $props = @{
                EmployeeID   = $_.EmployeeID
                Office       = $_.Office
                title        = $_.title
                Department   = $_.Department
                emailaddress = $_.emailaddress
                officephone  = $_.officephone
                manager      = $_.manager
                company      = $_.company
            Try {
                Get-ADUser -Identity $_.SamAccountName -Properties * -ErrorAction STOP| 
                    Set-ADUser @props -ErrorAction STOP
                Catch {
                    Write-Host "User '$acct' not found or failed to update: "
                    Write-Host $_

    EDIT: Added $<Underbar> to original $acct = $samaccountname # needed for error message

    2 people found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. Rich Matheisen 45,831 Reputation points

    Every one of those attributes have a corresponding parameter on the Set-ADUser cmdlet. You can do what you need in a few lines of code.

  2. Andreas Baumgarten 103.8K Reputation points MVP

    Hi @Naveen Kumar ,

    for the Set-AdUser command you will find the parameters and examples here: https://learn.microsoft.com/en-us/powershell/module/activedirectory/set-aduser?view=windowsserver2022-ps

    Here you will find some examples how to work with Set-AdUser and how to update multiple users using a csv file: https://lazyadmin.nl/powershell/set-aduser/

    If you started with your script and need some more help please ask and post your script (using the CodeSample option of the Q&A editor for the script (the icon with 101010)) together with the error message or details what isn't working properly.


    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Andreas Baumgarten