AD import users from CSV

·

2 min read

Here's an example format of the CSV for the import

FirstName,LastName,SamAccountName,UserPrincipalName,Password
John,Doe,jdoe,jdoe@example.com,Pa$$w0rd
Jane,Smith,jsmith,jsmith@example.com,Pa$$w0rd

Open PowerShell with administrative privileges

Search for PowerShell in the Start menu, right-click on it, and select "Run as administrator".

Load the AD PowerShell Module

Import-Module ActiveDirectory

Execute the Import Command

Use the Import-Csv cmdlet to read your CSV file and pipe it to the ForEach-Object cmdlet to process each user. Inside the loop, use the New-ADUser cmdlet to create the user accounts in Active Directory. Here's an example command:

Import-Csv "C:\path\to\your\users.csv" | ForEach-Object {
    New-ADUser -Name $_.FirstName -GivenName $_.FirstName -Surname $_.LastName -SamAccountName $_.SamAccountName -UserPrincipalName $_.UserPrincipalName -AccountPassword (ConvertTo-SecureString $_.Password -AsPlainText -Force) -Enabled $true
}

This command will create user accounts with the details specified in the CSV file. Make sure to adjust the file path to where your CSV is located.

After importing users into Active Directory, consider the following:

  • Verify the Import: Check a few user accounts manually in AD to ensure they were created successfully with the correct attributes.

  • Group Membership: You might need to add users to specific groups. This can be done manually or by modifying the script to include the Add-ADGroupMember cmdlet.

  • Set Additional Attributes: If your CSV contains additional attributes not covered in the import script, modify the script to include these attributes.

  • Password Policy: Ensure that the passwords provided in the CSV comply with your domain's password policy. Users may be required to change their password at first login depending on your policy settings.