≡ Menu

Create multiple test user accounts in active directory using PowerShell

In this article, I will show you how to create multiple test user accounts in active directory using PowerShell.

While playing with some stuff in my lab setup today, I got a requirement to have 100 test user accounts. I am not concerned much about the display name or any other properties of these test users and having names like user1, user2…user100 is enough in my case. I quickly looked around the options for doing this using PowerShell and finally settled with below approach as it seems much easy.

Since this is a very common requirement for anyone who are building and using their test labs for learning purpose, I thought of posting it here so that everyone can use it.

I used ActiveDirectory module that comes with Windows Server 2008 or above. It has cmdlet, New-ADUser, that simplifies the work. For this demonstration, I am creating user accounts from testuser1 to testuser100 with common password(“testme123”). I am also enabling the accounts after creation. All the new accounts will be created under the OU called LABAccounts at the room of my domain ad.techibee.com

You can copy paste the below code into a PowerShell window in your test lab and change –Path parameter to match your OU structure where you want to place the accounts and execute the script. You will see test accounts with in a minute.

Import-Module ActiveDirectory            
foreach($i in 1..100) {            
$AccountName = "TestUser{0}" -f $i            
$Password = Convertto-secureString -string "testme123" -AsPlainText            
New-ADUser -Name $AccountName -AccountPassword $Password -Path "OU=Labaccounts,DC=ad,DC=techibee,DC=com" -Enabled:$true            

Please note this above code is for lab purpose only where you want 100 or 1000 dummy user accounts for testing purpose. If you want to create users in production environment, you might want to set the required attribute values accordingly (like display name, telephone, etc).

{ 0 comments… add one }

Leave a Comment