Update multiple AD attributes with powershell via CSV

Claire McInally 0 Reputation points
2023-01-11T10:58:11.83+00:00

Good morning (first time poster here)

I am a beginner with Powershell and I would like to be able to update all AD users (1600) and multiple attributes via CSV file. The CSV contains the following data:

samaccountname,Description,Office,Department,Title,Company,Manager,employeeID

Can I please have some input on the best way to do this from a beginners perspective. If possible, I would also like this to include any issues with users that have been missed or skipped. I have an export of AD that I know have missing attributes so I plan on testing a few of these accounts first, before implementing to the whole user OU in AD.

Many thanks in advance

C

Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
6,811 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Rafael da Rocha 5,176 Reputation points
    2023-01-11T11:18:18.4466667+00:00

    Hello ClaMac23,

    this is the barebones to import the CSV and set the information in AD to what's on the file:

    $users = Import-Csv 'UserInfo.csv'
    
    foreach ($user in $users) {
        Set-ADUser -Identity $user.Samaccountname -Description $user.Description -Office $user.Office -Department $user.Department -Title $user.Title -Company $user.Company -manager $user.manager -employeeID $user.employeeID
    }
    
    

    Take care with the manager property, as it has to be in a specific format, just the display name won't work.

    More information about the Set-ADUser cmdlet:

    [https://learn.microsoft.com/en-us/powershell/module/activedirectory/set-aduser?view=windowsserver2022-ps

    0 comments No comments

  2. Claire McInally 0 Reputation points
    2023-01-11T12:10:38.8433333+00:00

    Thank you so much for getting back to me Rafael! I will take a look over this too :)

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.