Update to my create LAB users Powershell Script–Multiple Domains and 500 more users!…

by Andy Grogan on December 4, 2011 · 5 comments

in Exchange 2007 Scripts, Exchange 2010 (LAB), Exchange 2010 Scripts, Powershell, Test Labs

I have been making some modifications to my home lab over the last few days, one key change has been to add in a child domain so that I can test Exchange related scenarios in a multi-domain environment.

Naturally, once I had created the child domain, I wanted to populate it with some users – so out came my Powershell Lab users script – with a new CSV file with over 500 unique names within it for the domain.

I executed the script against my new child domain, and it was at this point where I discovered a flaw in the original code logic.

The original script detected the Active Directory domain using the following lines of code:

$domain = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()
$DomainDN = (([System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()).Domains | ? {$_.Name -eq $domain}).GetDirectoryEntry().distinguishedName

Which is OK if you are using a single domain and forest, however – if you have a multiple Parent / Child domain configuration and execute the script in the child domain – all the accounts are created in the Parent as the lines above will only detect Parent Domain in the Forest.

Therefore I changed the above lines to the following;

$domain = [System.DirectoryServices.ActiveDirectory.Domain]::GetComputerDomain()   
$DomainDN = (([System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()).Domains | ? {$_.Name -eq $domain}).GetDirectoryEntry().distinguishedName

The changes above change the scope of the of the Active Directory lookup to the Active Directory domain which the local computer is a member of.

The script can now be executed from within any domain (either parent or child), and will create accounts correctly.

Usage

Please refer to the original article here for instructions: http://www.telnetport25.com/2009/12/quick-post-%e2%80%93-script-to-create-lab-users-%e2%80%93-powershell-version%e2%80%a6/

Download

You can download the script from the following location – the Self-Extracting file contains the updated Powershell Script file and two sample CSV files which have over 800 user names. I have separated the user accounts into two files in case you have a number of domains (and you obviously would not want the same user accounts in each domain!)

ESEUtilGUIIcoCreate-Users.exe [ 150KB ]

{ 2 comments… read them below or add one }

Carlos Rotver December 5, 2011 at 6:02 pm

Hello Andy,

By any chance, do you have an script for Windows Server 2008, to create multiple users in bulk?? The thing is that I need to fill quite a few details (department, address, zip, etc) of each user (about 800) and don´t want to do it manually.

Kind Regards,

Reply

Zay June 29, 2013 at 2:19 pm

Hey Andy, Rich Prescott has created a PS tool that I use from time to time that will do what you desire (no disrespect Josh). Here is the link (http://gallery.technet.microsoft.com/scriptcenter/New-User-Creation-tool-14fa73cd) In case the link is removed, search ANUC on the web.

Reply

Leave a Comment

*

{ 3 trackbacks }

Previous post:

Next post: