Wanderer (drnuke) wrote,

Populating Test Labs with User Accounts…

Взято отсюда: http://www.telnetport25.com/component/content/article/2-catexchange2003/241-populating-test-labs-with-user-accounts.html

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 here, here, here, here and finally here.

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:

  • 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
 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:
LabUsers.csv – 389 Fictonal People just for you!
LAB_CreateUsers.vbs – 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 “LBUsers
Then create a new Organizational Unit in Active Directory called “ExchangeUsers” – 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 (User Principle Name) 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 – see below

When the replace dialog box appears in the “Find What” area type in: “@ldn.com” (without quotes) and then in the “Replace with” 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 “Replace with” area – see below

Click on the “Replace All” 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 Lab_CreateUsers.vbs file – which when first launched will prompt you for the following information:
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 “OK” button.
You will then be presented CSV filename dialog box – enter in LabUsers.csv and then click on the “OK” button.
Then you will be prompted for the target OU that you wish to use this should be entered in the format of “OU=ExchangeUsers” (without quotes) – if you have placed your OU inside a parent OU then the format will change to “OU=ExchangeUsers,OU= ” – again without quotes.
When you are happy with your OU settings click on the “OK” button.
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:
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:

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(”LDAP://rootDSE“)
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.SetPassword sPassword
  strUser.Put “userAccountControl”, 512


WScript.Echo “Script Completed - Hit F5 in the OU that you selected”

Tags: ad, create users, exchange server 2007, script
  • Post a new comment


    default userpic

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 1 comment