Script from CVS file to Active Directory and whats wrong with this script

I dont know how to do this

Write a PowerShell Script to Create AD User Accounts from a CSV file (located on the desktop) How do you do that?

1 Like

Hi Cameron,

It should look more like this:

# Import the AD Module
    Import-Module ActiveDirectory

# Get the path to the CSV file
    $filepath = Read-Host -Prompt "Enter your CSV file path"
    $Users = Import-csv $filepath 

# Import the CSV file as an array
    ForEach ($user in $user) {

# Do this for each user
    New-ADUser `
       -Name ($user.'First Name' + " " + $user.'Last Name') `
       -GivenName $user.'First Name' `
       -UserPrincipleName ($user.'First Name' + "," + $user.'Last Name' `
       -AccountPassword (ConvertTo-SecureString "Your Password" -AsPlainText -Force) `
       -Path "OU=Domain Users,OU=ServerAcademy,DC=ServerAcademy,DC=Local" '
       -ChangePasswordAtLogon 1 `
       -Enabled ([System.Convert :: ToBoolean($user.Enabled))
1 Like

-UserPrincipalName “Bradley.Beal”
not -userprincipalname “bradley, beal”


How about this im still getting errors

1 Like

Cameron, It looks like on line 11 where you have New-ADUser you are missing the ` at the end of the line to carry over to the next line. Also of note for when I did this lab. The OU listed in the CSV still listed Instructor Paul but the AD had Server Academy. Paul said this was being fixed so just verify otherwise it won’t import to an OU that isn’t already there. Good luck.

1 Like

it is UserPrincipalName
not userprinipalname

1 Like

I was able to get through the create AD user using powershell part of the lab. Where I’m having an issue is with the csv part of the lab. The OU is listing instructor Paul. For those who were able to complete the lab how can I change the OU to server academy. Thanks!

1 Like

good question

1 Like

I’m not sure how recently you look at the script @erikadelacruz21, but we updated it last week or the week before to show where you can change the target OU.

We show how to find this value at 4:30 of the video lesson below:


Follow the same steps and you will get the unique path you need for your specific environment.

Gonna try this. thanks so much!

1 Like