PowerShell: Add users to Active Directory

Quickie script to add a load of users to Active Directory. This was to generate a set of test users, so the account settings are rather scarce.

You have to convert the password text string to data type System.Security.SecureString, which I’m doing inline. If you just use a text string for the password you’ll get a “Cannot convert” error.

for ($i = 1; $i -lt 10; $i++)
    Write-Host ("User"+$i)
    New-ADUser -DisplayName "User$i" -AccountPassword (ConvertTo-SecureString -AsPlainText "Pa55w0rd" -Force) -Name "User$i" -Enabled $true

Note that if you run the script on a domain controller, you need to be running PowerShell “As Administrator” or you’ll get an “Access is denied” error. If you run the script from elsewhere you just need permission to create the accounts.


This entry was posted in PowerShell and tagged , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.