0%

0/1 Lessons

Course Introduction

• 1min

0 / 1 lessons complete

Getting Started with Active Directory Domain Services

• 52min

0 / 6 lessons complete

Introduction to Active Directory Users & Computers

• 1hr 27min

0 / 10 lessons complete

Adding a Second Domain Controller

• 1hr 31min

0 / 7 lessons complete

Active Directory Backups

• 1hr 24min

0 / 5 lessons complete

How to Administrate Active Directory with Windows PowerShell

• 1hr 58min

0 / 7 lessons complete

Administrating AD SS (Active Directory Sites and Services)

• 1hr 3min

0 / 5 lessons complete

Active Directory Trusts

• 54min

0 / 5 lessons complete

Modifying the Active Directory Schema

• 43min

0 / 3 lessons complete

Course Conclusion

• 2min

0 / 1 lessons complete

Creating User Accounts from a CSV (Comma Separated Value) File

Instructions

Q&A (0)

Resources (3)

Saving Progress...

In this lecture, I am going to be showing you how you can create active directory users from a CSV file.

I am going to show you how the CSV file looks like and you can find it in the resources of this lecture called NewUsers.csv.

You can see header fields like First Name, Last Name, Job Title, Office Phone, Email Address, Description, the target Organizational Unit or where they need to be placed within Active Directory and whether or not the account should be Enabled once it's created.

So, we are going to use PowerShell to automatically create all these user accounts. These are just 10 users here but if we were working with 500 or a thousand this will also work.

Log into the IPDC01 server and I have the file already saved into my E:\ drive.

We open Windows PowerShell ISE by clicking on the Windows icon on the bottom left and typing powershell and selecting Windows PowerShell ISE.

And the Windows PowerShell ISE opens up.

Let’s start typing out the script with the following:

# Import the AD Module

Import-Module ActiveDirectory

# Get the path to our target CSV file

$filepath = Read-Host -Prompt "Please enter the path to the CSV file that contains the new user accounts"

# Import the CSV as an array

$users = Import-CSV $filepath

Press the Play button to execute the script.

Note that in the bottom pane we have the script executed and it is asking for the path to the CSV so we type in E:\NewUsers.csv and press the Enter key on your keyboard.

The script finishes executing.

Now we need to do something with that information. Let’s add to our script the following:

# Import the AD Module

Import-Module ActiveDirectory

# Get the path to our target CSV file

$filepath = Read-Host -Prompt "Please enter the path to the CSV file that contains the new user accounts"

# Import the CSV as an array

$users = Import-CSV $filepath

# Complete an action for each user in the CSV file

ForEach ($user in $users) {

# Do this for each user

echo $user.'First Name'

}

Execute the script by clicking the Play icon and enter the CSV path during script execution.

The output of the script shows the First Name column of the CSV file.

Now let’s continue with the script adding the following line now:

# Import the AD Module

Import-Module ActiveDirectory

# Get the path to our target CSV file

$filepath = Read-Host -Prompt "Please enter the path to the CSV file that contains the new user accounts"

# Import the CSV as an array

$users = Import-CSV $filepath

# Complete an action for each user in the CSV file

ForEach ($user in $users) {

# Do this for each user

echo $user.'First Name'

echo $user.Description

}

Execute the script by clicking the Play icon and enter the CSV path during script execution. 

We can see that by adding the Description we have after the First Name, the Description from the CSV file.

We can see that so far the script is working as we expect.

So, what we can do now is create a new user account. Let’s type the following code:

# Import the AD Module

Import-Module ActiveDirectory

# Get the path to our target CSV file

$filepath = Read-Host -Prompt "Please enter the path to the CSV file that contains the new user accounts"

# Import the CSV as an array

$users = Import-CSV $filepath

# Complete an action for each user in the CSV file

ForEach ($user in $users) {

# Do this for each user

New-ADUser `

-Name ($user.'First Name' + " " + $user.'Last Name') `

-GivenName $user.'First Name' `

-Surname $user.'Last Name' `

Server Academy Members Only

Sorry, this lesson is only available to Server Academy Full Access members. Become a Full-Access Member now and you’ll get instant access to all of our courses.

5 2 votes
Lesson Rating
Subscribe
Notify of
10 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

profile avatar
Christian Sanchez(@christians)
Member
1 year ago

Hello, sorry if I am missing something but I do not see the CSV listed under resources. I downloaded both resources (CreateADUsersFromCSV & CreateADUsersFromCSVExpanded) and found 2 PS scripts but no CSV.

profile avatar
Adi Nugroho(@adin)
Member
10 months ago

Sorry, I want to ask. Is using quotation mark with a single(‘ ‘) or (” “) has the same meaning or different?

profile avatar
Adi Nugroho(@adin)
Member
Reply to  Ricardo P
10 months ago

Ok, thank you  👍 

profile avatar
ket2(@ket2)
Member
7 months ago

Hi, I did try to import CSV file, and it imported and I am able to echo any names or emails, but I can’t get it working in the foreach loop.

profile avatar
ket2(@ket2)
Member
Reply to  Ricardo P
7 months ago

Hi, I figured out.

profile avatar
blinkkk(@alwidelgadoa)
Member
4 months ago

Hi Ricardo,

how does the computer knows it has to create the users in the user OU? what if i wanted to creat a couple group, how would I indicate in the script to do so?