Creating test accounts in Active Directory

There’s often a need to create test accounts in AD. You may want to create a a set of test accounts or if you have a demo/test lab you may need accounts in that. Creating the names for the accounts is a pain unless you go down the test1, test2 etc route.

One way to real looking names is iuse a couple of loops like this

$fnames = @(
'Don'
'James'
'Jason'
'Jeff'
'Steve'
'Will'
'Dave'
'Bill'
'Mick'
'Fred'
)

$lnames = @(
'Jones'
'Smith'
'Brown'
'Black'
'White'
'Green'
'Wood'
'Bell'
'Harris'
'Fox'
)

$secpass = Read-Host -Prompt 'Password' -AsSecureString
$ou = "OU=UserAccounts,DC=Manticore,DC=org"

foreach ($fname in $fnames){
  foreach ($lname in $lnames){
    $name = $lname.TOUpper() + " $fname"
    $sam = "$fname$lname"
    $upn = "$sam@manticore.org"

    New-ADUser -Name $name -SamAccountName $sam -UserPrincipalName $upn -AccountPassword $secpass -Path $ou -Enabled $true
  
  }
}

First create an array of first names & another array of second names

Get a secure string for the Password – I’m using the same password for all as its my demo/test environment

Set the OU you want the accounts in.

Iterate over the set of first names and in that loop iterate over the last name. Within the inner loop create the name, samAccountName and UPN and call New-ADUser.

You end up with a set of new accounts where every first name is joined with every last name to create accounts. Names look a bit samey but for demo environment it works. Also, saves you having to think up individual names.

I’ve used   10 names in each of the first and last name arrays so end up with 100 new accounts.

Advertisements
This entry was posted in PowerShell and Active Directory. 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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s