Creating Test Accounts on a Windows 2008 R2 DC with PowerShell
Wednesday, April 11, 2012 at 12:00PM
Carlos Perez

Recently I had to rebuild my lab do to that I had cloned a bunch of VM’s and forgot to run sysprep on them. This caused problems do to link SID’s when I installed Exchange 2010 in my home lab so I decided to rebuild the whole AD and services in it. So I decided to share how I created 100 test accounts on an isolated part of my lab network.

After installing the Active Directory Service and making the changes to DNS so it would forward to the proper DNS and made sure I had a Reverse Lookup Zone I wanted to create 100 test domain accounts. I normally use cmd.exe with dsadd.exe command, but this time I wanted to do it using PowerShell and this is with what I came up with as a command:

  1: import-module activedirectory
  2: (1..100) | foreach {New-ADUser -SamAccountName "User$($_.tostring())" -Name "User$($_.tostring())" -DisplayName "User$($_.tostring())" -AccountPassword (ConvertTo-SecureString -AsPlainText "P@ssword$($_.tostring())" -Force) -Enabled $true -EmailAddress "user$($_.tostring())@acmelabs.com" }

The commands are broken as so:

I do hope you find this useful and informative as always.

Article originally appeared on Security and Networking (http://darkoperator.squarespace.com/).
See website for complete article licensing information.