Adding 285 Contoso Users with Pictures to your Development Environment Active Directory
October 25, 2011 9 Comments
While I love the Information Worker Demo VMs that Microsoft make available, I really wish they would hang around more than the really short expiry they are currently set to, and besides while I like the stuff they have in their VMs I do not need all of it for my work.
What I really like is the pre-populated Contoso Active Directory, with all of the users, properties and profile pictures pre-populated. I like it so much I took the time to export all of the values and code up a script that will add them into just about any Active Directory environment.
###################################################################################
# Title : Create Contoso Users in Active Directory
# Author : Mark Rhodes - markrhodes@gmail.com - @mrhodes
#
# Purpose : Creates 270+ users in Active Directory copied from the Contoso Information Worker Environment
#
# To Use : Extract all files and run "CreateUserAccounts.ps1 from an Administrative PowerShell prompt.
#
# Requirements :
# Active Directory RSAT tools installed.
# User Account with sufficient privilegse to create accounts in "USERS" Container.
#
# Files :
# CreateUserAccounts.ps1 - PowerShell Script
# ADUsers.csv - CSV file with all Active Directory properties
# Folder UserImages - 270 Images of users to be populated into the thumbnailPhoto property
#
# Warning! - Do not use this on a production directory.
###################################################################################
#Import Active Directory Module
Import-module activedirectory
#Autopopulate Domain
$dnsDomain =gc env:USERDNSDOMAIN
$split = $dnsDomain.split(".")
if ($split[2] -ne $null) {
$domain = "DC=$($split[0]),DC=$($split[1]),DC=$($split[2])"
} else {
$domain = "DC=$($split[0]),DC=$($split[1])"
}
#Declare any Variables
$dirpath = $pwd.path
$orgUnit = "CN=Users"
$dummyPassword = ConvertTo-SecureString -AsPlainText "P@ss1W0Rd!" -Force
$counter = 0
#import CSV File
$ImportFile = Import-csv "$dirpath\ADUsers.csv"
$TotalImports = $importFile.Count
#Create Users
$ImportFile | foreach {
$counter++
$progress = [int]($counter / $totalImports * 100)
Write-Progress -Activity "Provisioning User Accounts" -status "Provisioning account $counter of $TotalImports" -perc $progress
if ($_.Manager -eq "") {
New-ADUser -SamAccountName $_.SamAccountName -Name $_.Name -Surname $_.Sn -GivenName $_.GivenName -Path "$orgUnit,$domain" -AccountPassword $dummyPassword -Enabled $true -title $_.title -officePhone $_.officePhone -department $_.department -emailaddress $_.mail
} else {
New-ADUser -SamAccountName $_.SamAccountName -Name $_.Name -Surname $_.Sn -GivenName $_.GivenName -Path "$orgUnit,$domain" -AccountPassword $dummyPassword -Enabled $true -title $_.title -officePhone $_.officePhone -department $_.department -manager "$($_.Manager),$orgUnit,$domain" -emailaddress $_.mail
}
If (gci "$dirpath\userimages\$($_.name).jpg") {
$photo = [System.IO.File]::ReadAllBytes("$dirpath\userImages\$($_.name).jpg")
Set-ADUSER $_.samAccountName -Replace @{thumbnailPhoto=$photo}
}
}
I’ve made a zip file available that contains :
1 CSV file populated with all the values required.
1 PS1 file with the full script to create these users
1 Folder with 285 user images
All you need to do is unzip these, and run the PS1 file with PowerShell. By default my script puts each user into the USERS container, however if you wish to change this, just modify the $orgUnit variable.
The script can be downloaded from my public dropbox here. It is approximately 14 MB due to the large amount of photos contained within.
Update – 26/10/2011 – Fixed a couple of minor bugs, including one that stopped this working on any domains with three parts in the domain name.

Excellent script! I have a feeling using it will be a much more pleasant process than weeding through the msft vms.
Hi,
there is a typo in a dowloadable script. Insted of OU=”Users” it is written CN at the $orgUnit variable.
Thank you for the script. It is awesome
Hi Robi,
This is fixed up, on my demo environments I actually create a new container for my Users, hence the error
Cheers,
Mark
Yep, that’s still broken on the download. Changing it to OU=Users works, this script is great.. thanks for your work on it!
Hm
I got all accounts imported, but cant login with any!
If i reset the PW it works. is ther any mismatch between script generated pw and hand set?
Why use convert instead of “-AsSecureString” ?
Maybe this fix it?
Odd, first time I have heard of problems logging in. Unfortunately I have been unable to replicate. I would suggest refownloading the scripts, as I periodically update them
You’re a great guy!
Thank you
Thanks, glad to hear this helped
Great script Mark! Now I finally have some serious profiles to show in SharePoint