Sign In
 
 
Go Search
 
Zach Rosenfield's SharePoint Blog > Posts > Generating Test Farms
Generating Test Farms

I recently had a reader submit a great concept question for how to possibly use PowerShell to script SharePoint admin tasks. Since I want to dive into his idea in more detail, I first need to setup a new farm to do my testing. Since I want this 'test' farm to be as real as possible, I needed to create endless fake data—especially lots of sites and webs. Then came a bright idea—why not script it! Since everyone needs sample sites, which can take a long to time to manually create, I created this simple PowerShell script. For those interested, the script is available for download here and copied out below (complete with a progress output bar)!

###########################################################
#
# Script to Populate Test Farm Data
#
# Params: -WebApplication <URL> **no trailing '/'
#             -OwnerEmail <Email>
#             -OwnerLogin <User Alias>
#             -SiteCount <Int> #number of sites to create
#             -[SubSites] <Int> #number of webs to create
#             -[RootName] <String> #optional: provide the base name of all custom sites. Default=="Site"
#             -[ManagedPath] <string> #optional: provide the managed path to use. Default=="Sites"
#
# Sample Usage: "Create 1000 sites, each with 2 subsites on "WebApp1":
# .\PopulateTestData.ps1 -WebApplication "http://webapp1" -SiteCount 1000 -OwnerEmail "foo@bar.com" –OwnerLogin "domain\foo" -SubSites 2

###########################################################

#setup STSADM var
$stsadm = "$env:programfiles\Common Files\Microsoft Shared\Web Server Extensions\12\BIN\STSADM.EXE"


#process input
$vars=@{}
for($i = 0; $i -lt $args.length; $i++){
if($args[$i].subString(0,1) -ne "-"){ "Did not understand $args[$i]"; return;}
$vars[$args[$i].subString(1)] = $args[$i+1];
$i++;
}

#verify
if($vars['WebApplication'] -eq $null){Write-Host -ForegroundColor "Red" "WebApplication Parameter is required "; Return; }
if($vars['SiteCount'] -eq $null){Write-Host -ForegroundColor "Red" "SiteCount Parameter is required "; Return;}
if($vars['OwnerEmail'] -eq $null){Write-Host -ForegroundColor "Red" "OwnerEmail Parameter is required "; Return;}
if($vars['OwnerLogin'] -eq $null){Write-Host -ForegroundColor "Red" "OwnerLogin Parameter is required "; Return;}

if($vars['RootName'] -eq $null){ $vars['RootName'] = "Site" }
if($vars['ManagedPath'] -eq $null){ $vars['ManagedPath'] = "Sites" }
if($vars['SubSites'] -eq $null){ $vars['SubSites'] = 2 }

#Create Site Collections
for($i=0;$i -lt $vars['SiteCount'];$i++){
$progress = [String]($i/$vars['SiteCount']*100);
$url = $vars['webapplication']+"/"+$vars['ManagedPath']+"/"+$vars['RootName']+$i;

Write-Progress -Id 1 -PercentComplete $progress -Activity "Creating Test Content" -Status "Creating Site ($i): $url";

$sTemp = &stsadm -o createsite -url $url -ownerlogin $vars['OwnerLogin'] -owneremail $vars['OwnerEmail'] -sitetemplate "STS#0"
if(!($sTemp -like "*Operation completed successfully*")){ Write-Host -ForegroundColor "red" "Site '$url' Failed!"}
else{ #Create subsites...
for($j=0;$j -lt $vars['SubSites'];$j++){
$suburl = $url +"/subweb"+$j;
     $progress = [String]($j/$vars['SubSites']*100);
Write-Progress -ParentId 1 -PercentComplete $progress -Activity "Creating SubWeb ($j):" -Status "$suburl";

     $sTemp = &stsadm -o createweb -url $suburl -sitetemplate "STS#0"

}
Write-Progress -ParentId 1 -PercentComplete 100 -Activity "Creating SubWebs for $url" -Status "Finished";
}
}

Comments

Ideal for those "under my desk" farms

This is much faster than trying to restore data from prod backups for a quick test farm.
Thanks!
at 12/20/2007 4:05 PM

Great Post

Love your postings. SharePoint administration gets a lot easyer by using PowerShell :).

Do you know that the rss feed is not up to date?
It only displays the webservice post.
at 1/29/2008 6:35 AM

Add Comment

Items on this list require content approval. Your submission will not appear in public views until approved by someone with proper rights. More information on content approval.

Title


Comments *


Name (required) *


Attachments
 
 
   
Real Time Web Analytics