A long time ago I posted a VBSCRIPT and CSV file which when executed created over 300 user accounts in Active Directory which was designed to give you a number of test accounts which could be used within a LAB environment to test Exchange Server.
As mentioned the original script was based around VBSCRIPT and Exchange 2003 and also required a little bit of manual intervention in order for it to work within your specific environment.
Predominantly it was designed to work against Windows 2000 / 2003 server AD environments – however as time has elapsed its underling functionality has been superseded with the advent of Powershell / Windows 2008 and Exchange 2007 and 2010 to the point that under certain system configurations it will no longer work.
Therefore given the above (and that I have been rebuilding my test lab) I am pleased to present to you with an updated CSV file and script (where the script is now Powershell based) – which supports the following scenarios:
- Can be executed via Powershell versions 1.0 and 2.0
- Can be run on the following Operating Systems: Windows 2008 and Windows 2008 R2 (will also support Windows 2003 with Powershell installed)
- The accounts created can be configured with mailboxes for Exchange 2007 and Exchange 2010
So, if you are creating a test lab which is based around the above technologies and would like an easy way to get over 300 unique accounts into your Active Directory environment please feel free to download the following file to either your LAB Domain Controller or Exchange Server:
The above file is a self extracting ZIP which when executed with extract two files to you Exchange Server / Windows 2008 Domain Controller.
When you have downloaded and extracted the scripts to your server – open a Powershell Console and navigate to the location where they are located – when there type in:
.\CreateUsersFromCSV.ps1 and then press – see below;

When the script executes you will be presented with a Windows “Open” dialog box – navigate to the location where you extracted the files and then choose the sample CSV – see below;

The script will then execute creating each user in your Active Directory Lab environment – the Default password is “Password1” – see below;

When the script has completed – open Active Directory Users and Computers – you will see a new OU called “ExchangeUsers” – within this OU are the new accounts that you can play with – see below;

I hope that you find the above useful.


























{ 21 comments… read them below or add one }
I tried to use av csv file with columns instead av , separated but it didnt work. Is there a way to use a column seperated file?
Its much easier to fill in the users then in Excel.
Regards!
Sorry Mathias, I am not sure I understand. When I construct the CSV file I use Excel and each of the properties are placed in columns. I then save the file as CSV. I am not sure what the problem is that you are describing?
Dear Andy,
Thanks for giving a wonderful script.
I had a question, when i used the and created user account, i noticed a difference between manual and using script account creation that in Active directory users and groups, “Name ” column while user created using script will show “sanAccount name ” but user created manually in ADS will full name ( Fist name & Last Name – normally display name) so what’s wrong in script. Please advice me.
Can you please provide me line by line discription of script, what’s $CN ,$SN
$CN = $User.samAccountName
$SN = $User.Surname
$Given = $User.givenName
$samAccountName = $User.samAccountName
$Display = $User.DisplayName
$LABUser = $UserPath.Create(“User”,”CN=$CN”)
Write-Host “Creating User: $User.samAccountName”
$LABUser.Put(“samAccountName”,$samAccountName)
$LABUser.Put(“sn”,$SN)
$LABUser.Put(“givenName”,$Given)
$LABUser.Put(“displayName”,$Display)
$LABUser.Put(“mail”,”$samAccountName@$domain”)
$LABUser.Put(“description”, “Lab User – created via Script”)
$LABUser.Put(“userPrincipalName”,”$samAccountName@$domain”)
$LABUser.SetInfo()
Thanks
Unais
unaischr@gmail.com
Hey Andy,
Thank you for being such a life save when it comes to Exchange. I’ve read a lot of your articles.
I have a question in regards to this scripts. The two lines below looks into the forest to get user account info:
$domain = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()
$DomainDN = (([System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()).Domains | ? {$_.Name -eq $domain}).GetDirectoryEntry().distinguishedName
This is great because it works just as described but is there anyway these two lines can be modified in case I have I forest with multiple child domains? When I ran the same script in a child domain, I got errors. I even tried to modify it to:
$domain = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
$DomainDN = (([System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()).Domains | ? {$_.Name -eq $domain}).GetDirectoryEntry().distinguishedName
but it didn’t work.
I’m new to powershell. So, can you please help out?
Tunde
Hiya Tunde, there is an update to the script that does exactly that located here: http://www.telnetport25.com/2011/12/update-to-my-create-lab-users-powershell-scriptmultiple-domains-and-500-more-users/
Cheers
A
Thanks Andy,
I was in the middle of Peter Bruzzese Exchange 2010 Traning he made bor Tainsignal. Peter had aleardy extracted fromt he MS Distribution disk all the files he need for Installation and others need for the course. I was used the MS Exchange 2010 DVD. Suddendly in discussion of the the Lab he goes to his “DVD” which is really on his C: driver and pull out you script. I scan the disk over and over again and could’t find it. He did mention that your name as the author of the Power Shell script but failed to mentione where to get it. I did a Google Search on “Andy Grogan” and found this web site. After prusing around a bit, I finally found this script. Tell Peter to get a URL cause he implied that it was in the MS distribution. It should be otherwise created the 300 users for the Course would have taken longer that the course. Anyway thanks for coming up with it. When I am ready to set up my production system, I use Excel and create my used in it and save the as a .csv file. Wala, all my users andd to the AD with one PS command. I’m stargin to lover PS and EPS but I’m an old DOS users anyway so it comes naturally.
Again thanks for sharing,
Grady Nelson
XTC Media Group LLC
Atlanta, GA
Studio City, CA
PS C:\> .\CreateLabUsers.ps1
File C:\CreateLabUsers.ps1 cannot be loaded. The file C:\CreateLabUsers.ps1 is not digitally signed. The script will no
t execute on the system. Please see “get-help about_signing” for more details..
At line:1 char:21
+ .\CreateLabUsers.ps1 <<<<
What is your Powershell execution policy set to? You should set it to “RemoteSigned”
CSV file containing SAMaccount name is Firstname_last name.
able to run script with firstname.lastname but it is not working with firstname_lastname.
please let me know where i need to do changes in the script.
$CN = $User.samAccountName
$SN = $User.Surname
$Given = $User.givenName
$samAccountName = $User.samAccountName
$Display = $User.DisplayName
$LABUser = $UserPath.Create(“User”,”CN=$CN”)
Write-Host “Creating User: $User.samAccountName”
$LABUser.Put(“samAccountName”,$samAccountName)
$LABUser.Put(“sn”,$SN)
$LABUser.Put(“givenName”,$Given)
$LABUser.Put(“displayName”,$Display)
$LABUser.Put(“mail”,”$samAccountName@$domain”)
$LABUser.Put(“description”, “Lab User – created via Script”)
$LABUser.Put(“userPrincipalName”,”$samAccountName@$domain”)
$LABUser.SetInfo()
$Pwrd = $User.Password
$LABUser.psbase.invoke(“setPassword”,$Pwrd)
$LABUser.psbase.invokeSet(“AccountDisabled”,$False)
$LABUser.psbase.CommitChanges()
Rupesh, what error message are you getting when you run the script?
Thanks
When i run the command, below message is appear
creating user: sAMaccountName
Script completed
Regards
Rupesh
the script run successfully.
wrong spell in the row.
regard
rupesh
Good script Andy,
How can this script be modified to select the mailbox database?
I want to import 3000 accounts across multiple databases.
thanks
hey,i am new to scripting.i executed the script it successfully executed but no OU was being created.please help me
Andy,
i tried even refreshing Active Directory Users and computers,but it’s not working can you please tell me something.
nope
no i didn’t even produce any errors
thanks Andy,
but it will take me a day’s time to get back to that server please provide me your mail id so that i can mail you the text file
I am working on a project for for my exchange server class our instructor wants us to find a script online for creating multiple users and OUs through the script and yours appears to be able to do this with a little modification just not exactly sure where I need to modify the script at cause I have to create 3 ous with a set amount of users in each ou but its been a while since I scripted so I am kind of stuck at the moment as to where in your script I will need to edit it or if will even be able to set the script up to do what I need it to do. So far the simple way that I see would be to break the excel script into 3 different excel scripts with the set amount of users in each one but I am not sure how I need to set this up in your script
ok after spending about an hour looking over your script I see what I need to do I just have 1 small issue I am not seeing in your script the location where you tell the script to pull the labusers.csv file cause I would just need to duplicate the OU creation and User creation in the script 2 more time and just define my OUs instead of the single OU you have and tell the script to look for my custom users lists in each section so it pulls the right about of users for each OU it creates.
If you can point out the section where you have the script point to labusers.csv I can modify the script to fit my needs for my project other wise I will just have to set the script to create the default OU and modify down the labusers.csv to my set amount of users and manually create the other 2 OUs and move the users into the OUs which will be painful
Lamont,
The filename of the CSFIle is retrieved from the Select-FileDialog function.
You will see this on line 37 ($Filename = Select-FileDialog…)
The content of the CSVFile is then imported into a variable called $UserInformation – see line 48:
$UserInformation = Import-CSV $Filename
From what you are trying to do, you could stop using the Select-FileDialog function and do the following:
$CSVFile1 =
$CSVFile2 =
$CSVFile3 =
And then have:
$UserInformation1 = Import-CSV $CSVFile1
$UserInformation2 = Import-CSV $CSVFile2
$UserInformation3 = Import-CSV $CSVFile3
Thanks,
Andy