Setting demo AD environments

Finally I will always have great AD demo environments with no accounts named TestUser01 or alike. ;) This is the outcome of the setting up test AD environments discussion we had this week. Darren and Rob suggested a couple of tricks on duplicating AD to a test lab, and xaegr provided a great link to US census information data on the most frequently used names, as well as a sample script I am re-using and enhancing below.

I basically took what xaegr suggested, added other properties to user accounts (first name, last name, city, department), and added code creating global security groups for each department and adding users into the groups. Here goes the code:

################################################
# Script to provision demo AD labs
# (c) Dmitry Sotnikov, xaegr
# Requires AD cmdlets
################################################

# Add AD cmdlets (should be downloaded from 
# http://www.quest.com/activeroles_server/arms.aspx
# and installed on the local workstation
# the script assumes the workstation is a part of the domain

Add-PSSnapin  Quest.ActiveRoles.ADManagement -ErrorAction SilentlyContinue

# set folder in which the data files are located
# this folder should contain files from
# http://www.census.gov/genealogy/names/names_files.html
# as well as cities.txt and departments.txt with the
# lists of cities and departments for the lab
cd c:\demofiles

# set OU for demo accounts
$OU = "ps64.local/test"
# number of accounts to generate
$num = 100

# read name files
$last = Get-Content dist.all.last | select -First 1000
$firstm = Get-Content dist.male.first | select -First 100
$firstf = Get-Content dist.female.first | select -first 100

# extract the names
$last = $last | where {$_ -match "^(\S+)"}|foreach-object {$matches[1]}
$firstf = $firstf | where {$_ -match "^(\S+)"}|foreach-object {$matches[1]}
$firstm = $firstm | where {$_ -match "^(\S+)"}|foreach-object {$matches[1]}

# read department and city info
$cities = Get-Content Cities.txt
$depts = Get-Content Departments.txt

# set up random number generator
$rnd = New-Object System.Random

function New-RandomADUser {
    # pick a male or a female first name
    if($rnd.next(2) -eq 1) {
        $fn = $firstm[$rnd.next($firstm.length)]
    } else {
        $fn = $firstf[$rnd.next($firstf.length)]
    }
    # random last name
    $ln=$last[$rnd.next($last.length)]

    # Set proper caps
    $ln = $ln[0] + $ln.substring(1, $ln.length - 1).ToLower()
    $fn = $fn[0] + $fn.substring(1, $fn.length - 1).ToLower()

    # random city and department
    $city = $cities[$rnd.next($cities.length)]
    $dept = $depts[$rnd.next($depts.length)]

    # Create and enable a user
    
    if ( ( Get-QADUser -SamAccountName ($fn.substring(0,1) + $ln) ) -eq $null ) {
    
        New-QADUser -Name "$fn $ln" -SamAccountName ($fn.substring(0,1) + $ln) `
                    -ParentContainer $OU -City $city -Department $dept `
                    -UserPassword "P@ssw0rd" -FirstName $fn -LastName $ln `
                    -DisplayName "$fn $ln" -Description "$city $dept" -Office $city `
                    | Enable-QADUser
    }
}

# Create 100 users
1..$num | ForEach-Object { New-RandomADUser }

# Create groups for each department
Get-QADUser -SearchRoot $OU | Group Department | ForEach-Object {
    New-QADGroup -Name $_.Name -SamAccountName $_.Name -ParentContainer $OU
}

# Add users to the groups based on their departments
Get-QADUser -SearchRoot $OU | Add-QADGroupMember -Identity { $_.Department }

The files for names can be found on the census page, the files for cities and departments I was using are attached (note that to increase probability of a certain department or city you just need to duplicate it a few times in the file) as well as the script code:

Let me know if there’s anything else you need for your demo environments!

Tags: , , , ,

About these ads

6 Responses to “Setting demo AD environments”


  1. 1 Sergey December 25, 2007 at 12:20 pm

    Cool!!!

    That’s almost exactly what we were using in the cscript environment, now it’s in the PowerGUI, that’s awesome!

  2. 2 Peter Kriegel November 28, 2012 at 3:45 pm

    Hello Dimitry!

    thank you very much for this work !

    I cannot download the cities.txt and department.txt files!
    Got message I have to join your Blog but how can I ?

    • 3 Dmitry Sotnikov December 6, 2012 at 6:48 pm

      I’ve just tried both and they opened just fine for me. Just click the links!

      Or create the text files yourself. There’s nothing fancy in them. Just text files with one item (city name or department name) per line.


  1. 1 Митя Сотников: по-русски о PowerShell и не только : Создаем демо-среду Active Directory Trackback on December 14, 2007 at 5:10 pm
  2. 2 Secure Networks » Blog Archive » Script to Set Up Test AD Lab Trackback on March 25, 2010 at 9:46 pm
  3. 3 Populating A Test Lab with AD Objects Using Windows PowerShell « Ted's Tangled Mind Trackback on March 28, 2012 at 12:41 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s




My Recent Tweets

RSS My company’s blog

  • Meet our iPad2 Winner, Bruce Burke
    Last month we ran our first sweeps contest and received over 30,000 entries in just 4 weeks! Below is a screenshot of the Facebook entries: After announcing the winner, Bruce Burke, I decided to get in touch and find out more about him and how he is using Jelastic for his projects. Hi Bruce, thanks [...]The post Meet our iPad2 Winner, Bruce Burke appeared fi […]
  • MongoDB Master Slave Replication
    As we’ve already told you in our previous post about MySQL master-slave replication the database replication offers various benefits depending on its type and the options you choose, but the common benefit of replication is the availability of data when and where it is needed.  As a result, your customers will experience improved availability of replicated d […]
  • Integration with NetBeans IDE
    Like millions of developers out there we really love NetBeans IDE, which lets you quickly and easily develop Java desktop, mobile, and web applications, while also providing great tools for PHP developers. That’s why we have created a Jelastic plugin for this platform. With the new Jelastic plugin for NetBeans IDE, you can work with your development, [...]Th […]
  • New Version of Jelastic – 1.9.1 Launched
    Today we announced the launch of a major new version of Jelastic. The new version, 1.9.1, features a CRON scheduler, the ability to schedule database backups, new notifications about running out of resources and the latest versions of software stacks (including PostgreSQL 9.2.4). The newly launched Jelastic 1.9.1 includes: CRON job scheduler, Scheduled datab […]
  • Jelastic Released Commercially by innofield!
    Switzerland is well know for chocolate, their army knives and creating fabulous watches. Thanks to innofield,  the Swiss will forever be known as the providers of the first Swiss based PaaS solution with their Flow App Engine (powered by Jelastic). This week, innofield came out of beta and launched commercially with Jelastic 1.9.1. “As Platform-as-a-Service […]
  • Play 1 vs Play 2 Framework
    Today’s guest post comes to you from our friend and user, Dane Marcelo, JArchitect product manager. He points out some interesting differences between the Play 1 and the Play 2 frameworks. So, let’s dive into this great post! Play is an open source web application framework, written in Scala and Java, which follows the model–view–controller (MVC) architectur […]
  • Cloud Software Stacks Market Share: April 2013
    It’s that time where we can share with you the updated statistics on databases, Java and PHP application servers as well as Java and PHP version popularity. Last month was hot here at Jelastic: we launched Jelastic in the Netherlands with the most technically advanced hoster in the country – info.nl and in Switzerland with our very [...]The post Cloud Softwa […]

Legal

The posts on this blog are provided “as is” with no warranties and confer no rights. The opinions expressed on this site are mine and mine alone, and do not necessarily represent those of my former employer - Quest Software, or my current employer - Jelastic or anyone else for that matter. All trademarks acknowledged.

© 2007-2013 Dmitry Sotnikov

Pages

December 2007
M T W T F S S
« Nov   Jan »
 12
3456789
10111213141516
17181920212223
24252627282930
31  

Follow

Get every new post delivered to your Inbox.

Join 65 other followers

%d bloggers like this: