PowerShell

Adding Users into Active Directory OU with PowerShell

By: Julius Santos | Published: December 5, 2022 | Edited: Jun 10, 2023

Active Directory Lab | PowerShell
Prerequisites:
  • I have a folder which contains a .csv file of around 30 randomly generated people. We will be injecting this file into the database after creating it. This will be the data that is placed inside the Organizational Unit we make in Active Directory.

  • I have Visual Studio Code downloaded as my IDE for creating my .ps1 (PowerShell) script

Adding Active Directory users from CSV File

PowerShell’s Import-Csv can be used for reading data from a CSV file.

We create a new variable named $NewADUsers and assign it to the result of Import-Csv

  • We then use ‘New-ADUser’ to add the user to Active Directory

  • While opening the CSV we are working on, we reference the column names to use in our script

  • loop through each of the users in our imported CSV file, we will need a ForEach block.