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

by Andy Grogan on December 4, 2011 · 6 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.


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/


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 ]

{ 3 comments… read them below or add one }

Leave a Comment


{ 3 trackbacks }

Previous post:

Next post: