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$" -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!


Leave a Reply

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

You are commenting using your 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

My Recent Tweets


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 - WSO2 or anyone else for that matter. All trademarks acknowledged.

© 2007-2014 Dmitry Sotnikov

October 2007
« Sep   Nov »

%d bloggers like this: