Adding 285 Contoso Users with Pictures to your Development Environment Active Directory

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.

About these ads

15 Responses to Adding 285 Contoso Users with Pictures to your Development Environment Active Directory

  1. claire says:

    Excellent script! I have a feeling using it will be a much more pleasant process than weeding through the msft vms.

  2. Robi says:

    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 :D

  3. ragesoft says:

    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?

    • Mark Rhodes says:

      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 :)

  4. Troma says:

    You’re a great guy!
    Thank you :)

  5. Boerke says:

    Great script Mark! Now I finally have some serious profiles to show in SharePoint :)

  6. Steve says:

    This is exactly what I’ve been looking for for my dev environment. Thank you, Thank you, Thank you!

  7. Jeroen says:

    Thanks for the script, it helped me a lot!
    I’ll buy you a beer if I meet you at a conference :)

  8. I ran your script on a Server 2012 Release Candidate with SP2013 Preview. AD seems to be populated correctly, user accounts are created in SP2013 correctly, except the user pictures don’t display. Anything I need to be checking here? BTW, I used the new Active Directory Import to create the SP user accounts, not User Profile Synchronization. That service is not started on my instance (need to fix that, would that have anything to do with my issue?)

  9. Pingback: Step by step : Building a multi-server SharePoint farm with VMware Workstation – Setup SharePoint, SQL service accounts and sample users « alexto.info

  10. Jon Badgett says:

    Thanks for this script. To the poster above me – if SP2013 is anything like SP2010, there are more steps to pulling in photos for users. Specifically, fully setting up User Profile Synchronization, MySites, and running a PowerShell Commandlet that imports the pictures into the MySite Host. Information on SP2013 is pretty thin at this point, so good luck!

  11. Pingback: Kirk Evans Blog

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 )

Google+ photo

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

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 1,962 other followers

%d bloggers like this: