zippy1981

Improved Slipstream script

May 5th, 2013
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <#
  2. .SYNOPSIS
  3.    Builds a SQL Server slipstream install.
  4. .DESCRIPTION
  5.    This script will take the various components of a SQL Server isntall (RTM binaries, SPs, CUs) and assemble
  6.      them to create a slipstream install.  To use this script, you will need the unextracted RTM binaries (.iso
  7.      or DVD media) and the executables for the SP and CUs you want to use.
  8.      Mike Fal (htp://www.mikefal.net) 2-28-2013
  9. .PARAMETER <paramName>
  10.    RTMSource - File path for the RTM source files
  11.      SPSource - File path for the Service Pack executables (if no value is passed, no SP will be added)
  12.      CUSource - File path for the Cumulative update executables (if no value is passed, no CU will be added)
  13.      OutputDir - filepath where slipstream will be written, directory will be created if it doesn't exist.
  14. .EXAMPLE
  15.    .\Build-Slipstream.ps1 -RTMSource "C:\Users\mfal\Downloads\en_sql_server_2008_r2_developer_x86_x64_ia64_dvd_522665"
  16.                                                     -SPSource "C:\Users\mfal\Downloads\2008R2SP1"
  17.                                                     -CUSource "C:\Users\mfal\Downloads\2008R2SP1CU2"
  18.                                                     -output "C:\SQL2008SP1CU2_Slipstream"
  19. #>
  20. param(
  21.     [parameter(Mandatory=$true)][string] $RTMSource,
  22.     [parameter(Mandatory=$false)][string] $SPSource = $null,
  23.     [parameter(Mandatory=$false)][string] $CUSource = $null,
  24.     [parameter(Mandatory=$true)][string] $OutputDir
  25. )
  26.  
  27. #function to extract and copy SPs and CUs
  28. function Modify-Source{
  29.     param($TYPE="PCU",$WORKDIR,$PATCHDIR)
  30.     if (!(test-path("$WORKDIR\$TYPE"))) {mkdir $WORKDIR\$TYPE }
  31.     if (!(test-path("$WORKDIR\$TYPE"))) {Throw "Error: Patch file destination not available"}
  32.     set-location $PATCHDIR
  33.  
  34.     # First the comprressed service packs
  35.     $PATCHFILES=get-childitem "$PATCHDIR\*" -include *_zip.exe
  36.     foreach($FILE in $PATCHFILES) { iex "7za x -y $FILE"; }
  37.    
  38.     $PATCHFILES=get-childitem "$PATCHDIR\*" -include *.exe -Exclude *_zip.exe
  39.     foreach($FILE in $PATCHFILES)
  40.     {
  41.         iex "./$($FILE.basename)$($FILE.extension) /x:""$WORKDIR\$TYPE"" /q"
  42.         Write-Host "Waiting for $FILE to extract..."
  43.         while (@(Get-Process $FILE.Name.Replace(".exe","") -ErrorAction SilentlyContinue).Count -ne 0)
  44.         {
  45.             Start-Sleep 1
  46.         }
  47.     }
  48.     Write-Host "Copying $TYPE files..."
  49.     robocopy "$WORKDIR\$TYPE" "$WORKDIR" setup.exe /ndl /nfl /njh /njs
  50.     robocopy "$WORKDIR\$TYPE" "$WORKDIR" setup.rll /ndl /nfl /njh /njs
  51.  
  52. if (test-path("$WORKDIR\$TYPE\x86")) {robocopy "$WORKDIR\$TYPE\x86" "$WORKDIR\x86" /XF Microsoft.SQL.Chainer.PackageData.dll /ndl /nfl}
  53. if (test-path("$WORKDIR\$TYPE\x64")) {robocopy "$WORKDIR\$TYPE\x64" "$WORKDIR\x64" /XF Microsoft.SQL.Chainer.PackageData.dll /ndl /nfl}
  54. if (test-path("$WORKDIR\$TYPE\ia64")) {robocopy "$WORKDIR\$TYPE\ia64" "$WORKDIR\ia64" /XF Microsoft.SQL.Chainer.PackageData.dll /ndl /nfl}
  55.  
  56. set-location $WORKDIR
  57. }
  58.  
  59. #Test path locations for validity
  60.  
  61. if (!(test-path($RTMSource + "\setup.exe"))) {Throw "SQL RTM Source does not exist!"}
  62. if (![String]::IsNullOrEmpty($SPSource) -and !(test-path($SPSource))) {Throw "Invalid Service Pack file location!"}
  63. if (![String]::IsNullOrEmpty($CUSource) -and !(test-path($CUSource))) {Throw "Invalid Cumulative Update file location!"}
  64. if (!(test-path($OutputDir))) {mkdir $OutputDir}
  65. if (!(test-path($OutputDir))) {Throw "Unable to create build directory!"}
  66.  
  67. #begin merge process, RTM
  68. Write-Host "Copying RTM..."
  69. robocopy "$RTMSource" "$OutputDir" /s /ndl /nfl /a-:r
  70. $startloc=pwd
  71. set-location $OutputDir
  72.  
  73. Copy-Item ".\x86\DefaultSetup.ini" ".\"
  74.  
  75. #merge Service Pack
  76. if(![String]::IsNullOrEmpty($SPSource))
  77. {
  78.     Modify-Source "PCU" $OutputDir $SPSource
  79.     "`n`nPCUSOURCE=`".\PCU`" `n" |Out-File "DefaultSetup.ini" -Append
  80. }
  81.  
  82. #merge Cumulative Update
  83. if(![String]::IsNullOrEmpty($CUSource))
  84. {
  85.     Modify-Source "CU" $OutputDir $CUSource
  86.     "`n`nCUSOURCE=`".\CU`" `n" |Out-File "DefaultSetup.ini" -Append
  87. }
  88.  
  89. #cleanup
  90. copy-item "defaultsetup.ini" .\ia64 -force
  91. copy-item "defaultsetup.ini" .\x64 -force
  92. copy-item "defaultsetup.ini" .\x86 -force
  93.  
  94. Set-Location $startloc
Add Comment
Please, Sign In to add comment