Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- .SYNOPSIS
- Builds a SQL Server slipstream install.
- .DESCRIPTION
- This script will take the various components of a SQL Server isntall (RTM binaries, SPs, CUs) and assemble
- them to create a slipstream install. To use this script, you will need the unextracted RTM binaries (.iso
- or DVD media) and the executables for the SP and CUs you want to use.
- Mike Fal (htp://www.mikefal.net) 2-28-2013
- .PARAMETER <paramName>
- RTMSource - File path for the RTM source files
- SPSource - File path for the Service Pack executables (if no value is passed, no SP will be added)
- CUSource - File path for the Cumulative update executables (if no value is passed, no CU will be added)
- OutputDir - filepath where slipstream will be written, directory will be created if it doesn't exist.
- .EXAMPLE
- .\Build-Slipstream.ps1 -RTMSource "C:\Users\mfal\Downloads\en_sql_server_2008_r2_developer_x86_x64_ia64_dvd_522665"
- -SPSource "C:\Users\mfal\Downloads\2008R2SP1"
- -CUSource "C:\Users\mfal\Downloads\2008R2SP1CU2"
- -output "C:\SQL2008SP1CU2_Slipstream"
- #>
- param(
- [parameter(Mandatory=$true)][string] $RTMSource,
- [parameter(Mandatory=$false)][string] $SPSource = $null,
- [parameter(Mandatory=$false)][string] $CUSource = $null,
- [parameter(Mandatory=$true)][string] $OutputDir
- )
- #function to extract and copy SPs and CUs
- function Modify-Source{
- param($TYPE="PCU",$WORKDIR,$PATCHDIR)
- if (!(test-path("$WORKDIR\$TYPE"))) {mkdir $WORKDIR\$TYPE }
- if (!(test-path("$WORKDIR\$TYPE"))) {Throw "Error: Patch file destination not available"}
- set-location $PATCHDIR
- # First the comprressed service packs
- $PATCHFILES=get-childitem "$PATCHDIR\*" -include *_zip.exe
- foreach($FILE in $PATCHFILES) { iex "7za x -y $FILE"; }
- $PATCHFILES=get-childitem "$PATCHDIR\*" -include *.exe -Exclude *_zip.exe
- foreach($FILE in $PATCHFILES)
- {
- iex "./$($FILE.basename)$($FILE.extension) /x:""$WORKDIR\$TYPE"" /q"
- Write-Host "Waiting for $FILE to extract..."
- while (@(Get-Process $FILE.Name.Replace(".exe","") -ErrorAction SilentlyContinue).Count -ne 0)
- {
- Start-Sleep 1
- }
- }
- Write-Host "Copying $TYPE files..."
- robocopy "$WORKDIR\$TYPE" "$WORKDIR" setup.exe /ndl /nfl /njh /njs
- robocopy "$WORKDIR\$TYPE" "$WORKDIR" setup.rll /ndl /nfl /njh /njs
- if (test-path("$WORKDIR\$TYPE\x86")) {robocopy "$WORKDIR\$TYPE\x86" "$WORKDIR\x86" /XF Microsoft.SQL.Chainer.PackageData.dll /ndl /nfl}
- if (test-path("$WORKDIR\$TYPE\x64")) {robocopy "$WORKDIR\$TYPE\x64" "$WORKDIR\x64" /XF Microsoft.SQL.Chainer.PackageData.dll /ndl /nfl}
- if (test-path("$WORKDIR\$TYPE\ia64")) {robocopy "$WORKDIR\$TYPE\ia64" "$WORKDIR\ia64" /XF Microsoft.SQL.Chainer.PackageData.dll /ndl /nfl}
- set-location $WORKDIR
- }
- #Test path locations for validity
- if (!(test-path($RTMSource + "\setup.exe"))) {Throw "SQL RTM Source does not exist!"}
- if (![String]::IsNullOrEmpty($SPSource) -and !(test-path($SPSource))) {Throw "Invalid Service Pack file location!"}
- if (![String]::IsNullOrEmpty($CUSource) -and !(test-path($CUSource))) {Throw "Invalid Cumulative Update file location!"}
- if (!(test-path($OutputDir))) {mkdir $OutputDir}
- if (!(test-path($OutputDir))) {Throw "Unable to create build directory!"}
- #begin merge process, RTM
- Write-Host "Copying RTM..."
- robocopy "$RTMSource" "$OutputDir" /s /ndl /nfl /a-:r
- $startloc=pwd
- set-location $OutputDir
- Copy-Item ".\x86\DefaultSetup.ini" ".\"
- #merge Service Pack
- if(![String]::IsNullOrEmpty($SPSource))
- {
- Modify-Source "PCU" $OutputDir $SPSource
- "`n`nPCUSOURCE=`".\PCU`" `n" |Out-File "DefaultSetup.ini" -Append
- }
- #merge Cumulative Update
- if(![String]::IsNullOrEmpty($CUSource))
- {
- Modify-Source "CU" $OutputDir $CUSource
- "`n`nCUSOURCE=`".\CU`" `n" |Out-File "DefaultSetup.ini" -Append
- }
- #cleanup
- copy-item "defaultsetup.ini" .\ia64 -force
- copy-item "defaultsetup.ini" .\x64 -force
- copy-item "defaultsetup.ini" .\x86 -force
- Set-Location $startloc
Add Comment
Please, Sign In to add comment