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: AD, AD cmdlets, Active Directory, Blogosphere, Examples, PowerShell, one-liner, oneliner, provisioning
Subscribe by email






-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)
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!