Promoting Code and Sites from Development to QA to Production using PowerShell

Below is an example of a way to re-create Sites, Libraries, deploy custom code from a Development environment to QA to Staging and finally Production, in a repeatable manner without having to keep multiple versions of PowerShell scripts. It reduces the possiblity of introducing errors.

It consists on one powershell script (which could call on multiple function scripts), which pulls environment varables from a xml file. you would have a separate xml file for each environment.

Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction "SilentlyContinue"

# use the following the determine location of this script file
$scriptPath = Split-Path -parent $MyInvocation.MyCommand.Path
$deploymentXml = $scriptPath + "\Xml\Deploy.xml"

# now load the deployment configuration data
[xml]$Data = get-content $deploymentXml
$iisRootPath = $Data.Deploy.Settings.IISRootPath
$Url = $Data.Deploy.Settings.Url
$Port = $Data.Deploy.Settings.Port
$AppPoolAccount = $Data.Deploy.Settings.AppPoolAccount
$Owner = $Data.Deploy.Settings.Owner
$WebAppName = $Data.Deploy.Settings.WebAppName
$SiteName = $Data.Deploy.Settings.SiteName
$SiteTemplate = $Data.Deploy.Settings.SiteTemplate

# Below is an example of Creating a Site Collection

if ($Port -ne "80")
	$Url = $Url + ":" + $port

Write-Host "`n Create Site Collection" -ForegroundColor Blue

New-SPSite $url -Template $SiteTemplate  -Name  $SiteName -OwnerAlias $Owner -Confirm:$false

Here is the sample XML file:

<?xml version="1.0"?>
    <SiteName>Site Name</SiteName>

The folder / file stucture for each environment (DEV, QA, PROD etc) would look like this:

Deployment Folder Structure

Where the Code Solution (WSP’s) and other deployment files would be placed in the DeployFiles folder, PowerShell Function scripts in the Functions folder and the configuration Deploy.xml file in the the Xml folder. The Deployment.ps1 script (and any functions) would remain the same for each environment.


Leave a Reply

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

You are commenting using your 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