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.

Fixing an orphaned Site Collection within Project Server 2010

I had the pleasure of getting to know Project Server 2010 a couple of months ago.  I am a big fan of the way this has been implemeneted, as a SharePoint 2010 Service Application based approach seems to make more sense than a completely seperate product.

During this installation I found out a few interesting things about Project Server :

  1. Do not try using Claim Based Authentication on your Project Server Web Application. It may look like it is working, but I assure you it is not.  Clicking around some of the less obvious areas of the site will probably reveal it is not working.
  2. Never, ever delete a /PWA Site Collection for any reason.  They look just like a normal SharePoint Site Collection, but doing this will leave you with an orphaned PWA site and will leave you scratching your head.  This also implies that PWA site collections cannot be backed up and restored by conventional SharePoint Site Collection Backups.
  3. If you try to convert Claims back to Classic mode (which is not supported), you will likely just break your PWA instance.

There is no really clear cut way to recover from an orphaned Site Collection, and it becomes a real pain as you cannot retract the PWA Service Application until you fix the orphaned Site Collection.

The short verison is it can be done with PowerShell with the following script :

$psi = get-spserviceapplication | where {$_.TypeName -like “*Project*”}
$a = $psi.Sitecollection | where {$_.SiteID -eq “0ce62ac4-d733-483f-b60b-ea7e75b104d4″}
$a
$a.Delete()
$a = $psi.Sitecollection | where {$_.SiteID -eq “0ce62ac4-d733-483f-b60b-ea7e75b104d4″}
$a

You will then be able to recreate or remove the Service Application, and just get on with Project life!

Follow

Get every new post delivered to your Inbox.

Join 1,102 other followers