Creating test AD users (improved)

One of the kicks of PowerShell is taking someone else’s script and making it even shorter. ;) This was exactly my first thought when I found this test AD user creation script by Austin (found via Bob).

Austin’s script is perfectly fine but you can make it shorter by getting rid of csv step and enabling the accounts on the fly.

So here’s how I would create 500 test user accounts:

1..500 | ForEach-Object {
New-QADUser -ParentContainer ps64.local/test -Name testuser$_ -SamAccountName testuser$_ -UserPrincipalName testuser$_@example.com -FirstName testUser$_ -LastName example$_ -UserPassword password_123 | Enable-QADUser
}

I think this is pretty self-describing. I am using the 1..500 cycle to get a collection of these 500 numbers, and then put them inside the string parameters (make sure you use double quotes!) in the ForEach-Object cycle. Finally the objects are passed to Enable-QADUser so the accounts get enabled.

Pretty cool, eh?

Tags: , , , , , , , ,

2 Responses to “Creating test AD users (improved)”


  1. 1 dmitrysotnikov October 23, 2007 at 5:59 pm

    -ParentContainer and -Name are the only two mandatory parameters. The rest are optional (although, obviously if you don’t set password, the accounts won’t get enabled)

  2. 2 Austin October 24, 2007 at 1:12 pm

    Hi Dmitry,
    I figured that out and mentioned it in the blog as well. The “trip” was in “using PoSH” to create the csv file and populated, in fewer lines than you could with VB. A futher reflection on possibilities and flexibility. Glad you picked up on it though!

    Regards!

Leave a Reply




View Dmitry Sotnikov's profile on LinkedIn

Archives

See you at:

Legal

The posts on this blog are provided “as is” with no warranties and confer no rights. The opinions expressed on this site are mine and mine alone, and do not necessarily represent those of my employer Quest Software or anyone else for that matter. All trademarks acknowledged.

© 2007 Dmitry Sotnikov