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

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 ]

Sharing is caring!:

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

  1. 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,

Leave a Reply to Carlos Rotver Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.