skip to Main Content

Bulk create AD Users with random passwords

In the previous article, we discussed how to Create Active Directory Users from CSV with PowerShell. After the article got published, a question got asked by a reader. The question is as follows: Is it possible to automate the password workflow when creating new AD Users? The answer is: Yes, it’s possible. We can automate the passwords with PowerShell. In this article, you will learn how to bulk create AD Users with random passwords.

Before you start to bulk create AD Users

In the article, we are going to use the following files:

File Info
NewUsersRP.csv CSV template that contains the user accounts information
Add-NewUsersRandomPasswords.ps1 PowerShell script that will create user accounts with random passwords

How it works

The PowerShell script will automatically create AD users from CSV file and generate random passwords for the users. After the user accounts are created with random passwords, a new CSV file will be exported. In that file, you will have the passwords column with the created passwords.

Prepare Add-NewUsersRandomPasswords PowerShell script

Before you start, you want to place the files in the right place. We recommend creating two folders with the name Scripts and Temp on the C:\ drive of the Management Server or Domain Controller.

Download the Powershell script Add-NewUsersRandomPasswords.ps1 (direct link). Save the file in the path C:\Scripts\.

  • Change line 7 if you are willing to place the CSV file to a different path then C:\scripts\.
  • Change line 10 if you want to export the CSV with passwords to a different path then C:\temp\.
  • Change line 13 to your UserPrincipalName (UPN). In our example, it’s exoip.com.

Bulk create AD Users with random passwords scripts folder

Download and edit CSV template

Download the CSV template NewUsersRP.csv (direct link). Save the file in C:\Temp\.

Bulk create AD Users with random passwords temp folder

Open the CSV file with your favorite editor. For example, Microsoft Excel. Edit the CSV file to your needs and save it.

Import CSV file in PowerShell

Before you start running the PowerShell script, it’s good to import the CSV file in PowerShell first. Run PowerShell as administrator. Change the directory to C:\temp\. Make use of the Import-Csv cmdlet.

If you don’t see all the information in the output, make use of the Out-GridView cmdlet.

It will show as below screen.

Bulk create AD Users with random passwords Out-GridView

If you get errors when importing the CSV file, troubleshoot further before proceeding to the next step.

Run Add-NewUsersRandomPasswords PowerShell script

Before running the script

Start Active Directory Users and Computers (ADUC). Good to know is that the script will not create the Organizational Unit (OU). Create the OU if you don’t have it in AD.

In our example, the OU with the name IT is created and is empty.

Bulk create AD Users with random passwords temp folder before

Let’s run the script to create AD users.

If you run the script and the user is already created in AD, you will get the following.

After running the script

The OU with the name IT is filled with new users.

Bulk create AD Users with random passwords temp folder after

New CSV file including the random passwords

A new CSV file will be created in the C:\temp\ folder. The CSV file will have the name Passwords with the date and time appended. For example, Passwords_13-09-2020_20384101.csv.

Open the CSV file with your favorite program. For example, Microsoft Excel. The CSV file will contain a new column with the name Initial Password. These are the generated passwords.

Bulk create AD Users with random passwords result

Did this help you to bulk create AD Users with random passwords?

Keep reading: Active Directory weak password checker »

Conclusion

To sum it up, you learned how to bulk create AD Users with random passwords. These random passwords are generated automatically with PowerShell. If you need to bulk create AD users, I recommend you to use this PowerShell script.

Did you enjoy this article? If so, you may like the article Bulk move AD users to another OU with PowerShell. Don’t forget to follow us and share this article.

ALI TAJRAN

ALI TAJRAN

ALI TAJRAN is a passionate IT Architect, IT Consultant, and Microsoft Certified Trainer. He started Information Technology at a very young age, and his goal is to teach and inspire others. Read more »

This Post Has 0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top