Creating a Slipstream SQL Server install media using #PowerShell


Slipstream is a term used to describe merging original source media with updates and then installing the updated files. Slipstreaming has been supported by Windows Operating systems for a while (by using update.exe with integrate parameter) but, has been added to SQL Server from SQL Server2008 service pack 1.

The major advantage is that Slipstreaming allows you to get to the latest supported version without having to patch upgrade your installation. Install; Upgrade; AddNode scenarios which are supported by the original media are still supported when you slipstream.

Before you use the script, kindly read the msdn entry; on how to do this manually.

There are couple of pre-requisites:

  • Microsoft Windows installer 4.5 or greater (msiexec /?)
  • Microsoft .NET Framework 3.5 SP1

The script is pretty straight forward but, there are certain assumptions. C:\SQL2008 or C:\2008R2 would be the folders where the install media is stored; you can change this. And the service pack will be stored in a folder called ‘SP’ inside the base folder. Also, the slipstreamed media will be stored in C:\SQL2008_SlipStreamNNNN; where NNNN is the version number of SQL Server after upgrade (the variable is $verPCU). So, without further delay; here we go:

Begin
{
	$isPCU = $true
	$isCU = $false
	$verPCU = "5500" # service pack version
	$verCU = $null
	$archArray = @('x64', 'x86', 'ia64')
	$prodPartialName = '08' # or it could be 08R2

	#Basepath is where you have the executables
	$basePath = "C:\SQL20" + $prodPartialName + "\"
	$patchExePath = "C:\SQL20" + $prodPartialName + "\SP"
	$basePathPCU = $basePath + "SQL2008_slipstream" + $slpStrmVer + "\PCU"
	$basePathCU = $basePath + "SQL2008_slipstream" + $slpStrmVer + "\CU"

	if($isPCU){
		$slpStrmVer = $verPCU
	}elseif($isCU){
		$slpStrmVer = $verCU
	}else{
		exit -1;
	}
}
Process
{
	#Copy your original SQL Server 2008 source media to "C:\SQL2008\SQL2008_slipstreamNNNN"
	$srcPath = $basePath + "SQL20" + $prodPartialName
	$destPath = $srcPath + "_slipstream" + $slpStrmVer
	try{
		#New-Item -Type directory -path $destPath -force ->not needed for now.
		Write-Verbose -message "Copying source media from: `n `t $srcPath `n `t(to) `n `t$destPath." -verbose
		Copy-Item $srcPath -Destination $destPath -recurse -force #copy-item creates the destination folder if it does not already exist.
	}catch{
		Write-Error "Failed to copy files source media from: `n `t $srcPath to $destPath"
		return -1;
	}

	if($isPCU)
	{
		try{
			#Extract the patchfiles to the PCU folder
			$patchPath = $patchExePath + $verPCU
			$patchFiles = Get-ChildItem -Path $patchPath -Filter "*.exe"
			foreach($patchFile in $patchFiles){
				$fullPath = $patchFile.FullName
				cmd /c "$fullPath /x:$basePathPCU"
				if($LASTEXITCODE -ne 0){throw "$LASTEXITCODE"}
			}

			#copy the setup.exe and setup.rll
			Copy-Item "$basePathPCU\Setup.exe" -Destination $destPath -Force
			Copy-Item "$basePathPCU\Setup.rll" -Destination $destPath -Force

			#Copy all files not the folders, except the Microsoft.SQL.Chainer.PackageData.dll
			foreach($archType in $archArray){
				$sourcePath = $basePathPCU + '\' + $archType
				$destinationPath = $destPath + '\' + $archType

				Get-ChildItem -Path $sourcePath -Exclude "Microsoft.SQL.Chainer.PackageData.dll" |
					Where-Object {$_.PSIsContainer -eq $false} |
					Foreach-Object { Copy-Item -force -path $_.Fullname -destination $destinationPath}

				#Update defaultsetup.ini file
				echo "PCUSOURCE=`".\PCU`"" >> "$destinationPath\DefaultSetup.ini"
			}
		}catch{
			Write-Error "Failed to extract patch files`n `t Errorcode returned is: $_"
			return -1;
		}
	}
}
Advertisements
About

By profession, I’m a SQL Server Database Administrator. I love to poke my nose into different corners and see how stuff looks in there. I keep looking for new things to do as my mind refuses to settle on one topic.

Tagged with: , ,
Posted in PowerShell, SQL Server

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

%d bloggers like this: