Skip to content

Instantly share code, notes, and snippets.

@altrive
Last active December 15, 2015 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save altrive/5327506 to your computer and use it in GitHub Desktop.
Save altrive/5327506 to your computer and use it in GitHub Desktop.
SQL Server 2012 SP1 Express Management Studio unattend offline installer.

Summary

Unattend install Script for SQL Server 2012 SP1 Express Management Studio.

Target Operating System

  • Windows 8
  • Windows Server 2012

Usage

1.Download SQL Server 2012 SP1 Express Management Studio

Download SQLManagementStudio_x64 and copy to network share -SQL Server 2012 SP1 Express:http://www.microsoft.com/en-us/download/details.aspx?id=35579

2.Download additional patches

SQL Server 2012 SP1 requires following patches.

3.Install Management Studio

Run following command to install Management Studio Express

$params = @{
    ImagePath = "\\172.16.0.1\Shared\Images\SQLServer2012_SP1"
    WinSxS = "\\172.16.0.1\Shared\Images\WindowsServer2012\WinSxs"
}
Install-ManagementStudio @params -Verbose

Note:
WinSxs folder parameter is needed for .NET Framework 3.5 offine install. If parameter is not set, it automatically download installer from WindowsUpdate.

function Install-ManagementStudio
{
[CmdletBinding()]
param(
$ImagePath,
$WinSxS
)
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$result = Get-WindowsOptionalFeature -FeatureName "NETFX3" -Online -Verbose:$false
if($result.State -ne "Enabled")
{
#Enable .NET Framework 3.5
Write-Verbose "Enable .NET Framework 3.5(Prerequisite) ..."
if($WinSxs -eq $null)
{
Write-Verbose "`tUse WindowsUpdate install source"
Enable-WindowsOptionalFeature -FeatureName "NETFX3" -Online -Verbose:$false | Out-Null
}
else
{
Write-Verbose "`tUse WinSxs install source"
Enable-WindowsOptionalFeature -FeatureName "NETFX3" -Online -LimitAccess -Source $WinSxS -Verbose:$false | Out-Null
}
}
#Install SQL Server2012 Express SP1 Management Studio
Write-Verbose "Install SQL Server2012 Express SP1 Management Studio..."
$installerPath = Join-Path $ImagePath "SQLManagementStudio_x64_*.exe" -Resolve
Join-Path $ImagePath "Updates" -Resolve | Out-Null #Check Path (UNC path with -Resove option append FileSystem provider path)
$updateSource = Join-Path $ImagePath "Updates"
$arguments = @(
"/ACTION=Install"
"/QUIETSIMPLE"
"/FEATURES=SSMS,ADV_SSMS"
'/UpdateEnabled="True"'
'/UpdateSource="{0}"' -f $updateSource
"/IAcceptSQLServerLicenseTerms"
)
Write-Progress -Activity "Install SQL Server 2012 SP1" -Status "Install..."
Start-Process -FilePath $installerPath -ArgumentList $arguments -Wait
Write-Progress -Activity "Install SQL Server 2012 SP1" -Complete
#$LastExitCode is not returned from installer. it need to check install log file.
$logPath = Join-Path $env:ProgramFiles "Microsoft SQL Server\110\Setup Bootstrap\Log\Summary.txt" -Resolve
$line = Get-Content $logPath -Encoding UTF8 | Select-String -SimpleMatch "Exit code (Decimal):"
if(($line.Line -match "Exit code \(Decimal\):\s*(?<ErrorCode>.+)"))
{
$errorCode =$Matches["ErrorCode"]
switch($errorCode)
{
0{
Write-Verbose "Install operation completed successfuly."
break
}
3010{
Write-Warning "Install operation completed successfuly. need to restart OS"
}
default{
Write-Error "Install operation failed. ExitCode = $errorCode, LogFile=$logPath"
breal
}
}
}
else
{
Write-Error "ExitCode is not found in log file. LogFile=$logPath"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment