Script to Create Lab Users – Powershell
[LEFT][CODE]http://www.telnetport25.com/component/content/article/15-powershell/321-quick-post-script-to-create-lab-users-powershell-version.html[/CODE]
A long time ago I posted a VBSCRIPT and CSV file which when executed created over [URL="http://www.telnetport25.com/component/content/article/2-catexchange2003/241-populating-test-labs-with-user-accounts.html"]300 user accounts in Active Directory[/URL] 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:
[LIST][*]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[/LIST]
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:
[IMG]http://www.telnetport25.com/images/stories/legimages/ESEUtilGUIIco.jpg[/IMG][URL="http://www.telnetport25.com/downloads/scripts/Create-Users.exe"]Create-Users.exe [ 142KB ][/URL]
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:
[FONT=Courier New].\CreateUsersFromCSV.ps1[/FONT] and then press – see below;
[IMG]http://www.telnetport25.com/images/stories/LabUsers01_5f0987bc-1298-4732-9f79-8bd56fbd1b6f.jpg[/IMG]
When the script executes you will be presented with a Windows “[B][I]Open[/I][/B]” dialog box – navigate to the location where you extracted the files and then choose the sample CSV – see below;
[IMG]http://www.telnetport25.com/images/stories/LabUsers02_40ac6689-d6b4-40fa-b507-a60c8da91e9a.jpg[/IMG]
The script will then execute creating each user in your Active Directory Lab environment – the Default password is “[B][I]Password1[/I][/B]” – see below;
[IMG]http://www.telnetport25.com/images/stories/LabUsers03_78ea47b2-7fc1-419b-bc9d-fc7766ecb018.jpg[/IMG]
When the script has completed – open Active Directory Users and Computers – you will see a new OU called “[B][I]ExchangeUsers[/I][/B]” – within this OU are the new accounts that you can play with – see below;
[IMG]http://www.telnetport25.com/images/stories/LabUsers04_fb8edfa2-1b57-43ec-95d1-efde08148ab9.jpg[/IMG]
I hope that you find the above useful
[/LEFT]
Populating Test Labs with User Accounts
[LEFT][CODE]http://www.telnetport25.com/component/content/article/2-catexchange2003/241-populating-test-labs-with-user-accounts.html[/CODE]
Those of you that have been following this blog will know that recently I have made a number of posts that are either based around the virtues of Test Labs or indeed that work that I have been doing in relation to them – for information my posts on the subject are [URL="http://telnetport25.wordpress.com/2007/08/27/test-lab-virtualisation-of-exchange-2007-ccr-cluster-using-vmware-part-1/"][COLOR=#7f1d1d]here[/COLOR][/URL], [URL="http://telnetport25.wordpress.com/2007/08/28/test-lab-virtualisation-of-exchange-2007-ccr-cluster-using-vmware-part-2/"][COLOR=#7f1d1d]here[/COLOR][/URL], [URL="http://telnetport25.wordpress.com/2007/08/29/test-lab-virtualisation-of-exchange-2007-ccr-clustering-using-vmware-part-3/"][COLOR=#7f1d1d]here[/COLOR][/URL], [URL="http://telnetport25.wordpress.com/2007/09/02/test-lab-virtualisation-of-exchange-2007-ccr-clustering-using-vmware-part-4/"][COLOR=#7f1d1d]here[/COLOR][/URL] and finally [URL="http://telnetport25.wordpress.com/2007/08/13/test-labs-a-nice-toy-or-an-essential-part-of-an-enterprise/"][COLOR=#7f1d1d]here[/COLOR][/URL].
Now one of the most daunting things about test labs, is not always the construction of the Domain, or indeed the creation of the servers within them, but how to you populate them with any meaningful user data as part of the Directory (e.g. creating a number of users).
In this article I would like to provide all of you with the following tools that will help you construct the users in your test lab:
[LIST][*]A CSV file with 389 unique users within it – this files contains the following data FirstName, Surname, samAccountName, Display Name, Password, and a UserPrincipleName[*]A VBSCRIPT that will parse the data in the CSV file and create 389 users account in your test LAB which are ready to be used as part of either an Exchange 2003 or Exchange 2007 test lab[/LIST]
Before I begin (and if you are interested in using this article) you will need to download the following files to your Exchange server or domain controller in your LAB:
[URL="http://www.telnetport25.com/legacySites/msex/LabUsers.csv"][COLOR=#7f1d1d]LabUsers.csv[/COLOR][/URL] – 389 Fictonal People just for you!
[URL="http://www.telnetport25.com/legacySites/msex/lab_CreateUsers.vbs"][COLOR=#7f1d1d]LAB_CreateUsers.vbs[/COLOR][/URL] – the script that parses the CSV file and creates the file in your directory.
When you have downloaded them place them in a Directory Called “[B]LBUsers[/B]”
Then create a new Organizational Unit in Active Directory called “[B]ExchangeUsers[/B]” – it is easier to make this OU in the root of your AD structure, however, the script can handle nested OU’s as well.
What you will need to do now is modify the UPN ([B]User Principle Name[/B]) for all users within the csv file – now, don’t panic you do not have to go through all 389 users – all you need to do is:
Open the CSV file on your server in NOTEPAD – then go to the Edit menu and select the replace option – [I]see below[/I]
[I][IMG]http://www.telnetport25.com/images/stories/legimages/np1.jpg[/IMG][/I]
When the replace dialog box appears in the “[B]Find What[/B]” area type in: [EMAIL="%E2%80%9C@ldn.com"][COLOR=#7f1d1d]“@ldn.com[/COLOR][/EMAIL]” (without quotes) and then in the “[B]Replace with[/B]” area type in the name of your test domain – “@” (without quotes) – so if you had a test domain called @billy.com, billy.com is what you would type into the “[B]Replace with[/B]” area – [I]see below[/I]
[I][IMG]http://www.telnetport25.com/images/stories/legimages/np2.jpg[/IMG][/I]
Click on the “[B]Replace All[/B]” button, NOTEPAD will then go away and replace all entries with the values that are relevant to your test lab domain.
When NOTEPAD is finished – save the file.
When you are happy with the content of the CSV file you can begin by double clicking on the [B]Lab_CreateUsers.vbs [/B]file – which when first launched will prompt you for the following information:
[IMG]http://www.telnetport25.com/images/stories/legimages/sc1.jpg[/IMG]
Enter in the full path to the CSV file (do not enter in the file name) and ensure that you add in the trailing slash for the path – then click the “[B]OK[/B]” button.
[IMG]http://www.telnetport25.com/images/stories/legimages/sc2.jpg[/IMG]
You will then be presented CSV filename dialog box – enter in [B]LabUsers.csv [/B]and then click on the “[B]OK[/B]” button.
[IMG]http://www.telnetport25.com/images/stories/legimages/sc3.jpg[/IMG]
Then you will be prompted for the target OU that you wish to use this should be entered in the format of “[B]OU=ExchangeUsers[/B]” (without quotes) – if you have placed your OU inside a parent OU then the format will change to “[B]OU=ExchangeUsers,OU= [/B]” – again without quotes.
When you are happy with your OU settings click on the “[B]OK[/B]” button.
[IMG]http://www.telnetport25.com/images/stories/legimages/sc4.jpg[/IMG]
When the script has completed, you will be presented with the dialog box above – go to Active Directory Users and Computers and navigate to the OU that you created and you should see something similar to the following:
[IMG]http://www.telnetport25.com/images/stories/legimages/sc5.jpg[/IMG]
At the end of this process you should now have 389 users, in an OU called “ExchangeUsers” ready to be part of your test lab.
For reference the following is the contents of the LAB_CreateUsers.vbs script:
[CODE]strCSVPath = InputBox(”Please enter in the full path to your CSV (PLEASE INCLUDE THE END SLASH \)”)
strCSVName = InputBox(”Please Enter in the FileName”)
strOU = InputBox(”Please Enter in the destination OU (FORMAT: OU=,OU=”)
set csvInputConn = createobject(”ADODB.connection”)
set csvInputRS = createobject(”ADODB.recordset”)
csvInputConn.Open “Provider=Microsoft.Jet.OLEDB.4.0;” & “Data Source=” & strCSVPath & “;” & “Extended Properties=”"text;HDR=NO;FMT=Delimited”"”
csvInputRS.open “SELECT * FROM ” & strCSVName,csvInputConn
Set RootLDAP = GetObject(”[URL="http://rootdse/"]LDAP://rootDSE[/URL]“)
Set ADLocation = GetObject(”LDAP://” & strOU & “,” & RootLDAP.Get(”defaultNamingContext”))
do until csvInputRS.EOF
On Error Resume Next
strFirstName = csvInputRS.Fields.Item(0).value
strSurName = csvInputRS.Fields.Item(1).value
strSam = csvInputRS.Fields.Item(2).value
strDisplayName = csvInputRS.Fields.Item(3).value
strPassword = csvInputRS.Fields.Item(4).value
strUPN = csvInputRS.Fields.Item(5).value
Set strUser = ADLocation.Create(”User”,”cn=” & strSam)
strUser.put “sAMAccountName”,strSam
strUser.put “givenName”,strFirstName
strUser.put “sn”,strSurname
strUser.put “UserPrincipalName”,strUPN
strUser.put “DisplayName”,strDisplayName
strUser.put “name”,strDisplayName
strUser.put “mail”,strUPN
strUser.SetInfo
strUser.SetPassword sPassword
strUser.Put “userAccountControl”, 512
strUser.SetInfo
csvInputRS.movenext
Loop
WScript.Echo “Script Completed - Hit F5 in the OU that you selected”
WScript.Quit
[/CODE][/LEFT]