Powershell Installation Scripts
<#
.SYNOPSIS
Install SQL2008R2 Server
.DESCRIPTION
use Switches to install SQL Server Features easy and silently
.PARAMETER instanceName
Name of SQL Instance
.PARAMETER useGerman
Install German Version of SQL Server (Managementstudio)
.PARAMETER installOnly
Use this parameter to only install Managementstudio or SQL Engine
.EXAMPLE
Install-SQL2008R2.ps1 -installOnly SQLEngine -useGerman
.Notes
File Name : Install-SQL2008R2.ps1
Author : Robert Rajakone
Date : 05. September 2013
#>
param(
[string] $instanceName="SQL2008R2",
[switch] $useGermanVersion,
[ValidateSet('SQLEngine', 'ManagementStudio')]
[string] $installOnly
)
#Changing to germany regional settings
if($useGermanVersion){ Start-Process -Wait -ArgumentList @("/c", "\\DOS-Scripts\change_locale_de-DE.bat") -FilePath cmd.exe }
#Switching Installer depending on Language
$Installer = "\\software\SQL Server Express Edition 2008R2\SQLEXPRADV_x64_ENU\setup.exe"
if($useGermanVersion){ $Installer = "\\software\SQL Server Express Edition 2008R2\SQLEXPRADV_x64_DEU.exe" }
# Gathering Features
$Features = @()
if($installOnly){
if($installOnly.equals("SQLEngine") ){
$Features +="SQLEngine"
$Features +="FullText"
}
if($installOnly.equals("ManagementStudio") ){
$Features +="SSMS"
}
}else{
$Features +="SSMS"
$Features +="RS"
$Features +="SQLEngine"
$Features +="FullText"
}
$FeatureList = $Features -join ","
$Args = @(
"/ACTION=Install"
"/IACCEPTSQLSERVERLICENSETERMS"
"/ERRORREPORTING=0"
"/FEATURES=$FeatureList"
"/INSTANCENAME=$instanceName"
"/QS"
"/SAPWD=secret-sa-password"
"/SECURITYMODE=SQL"
"/ADDCURRENTUSERASSQLADMIN"
"/RSINSTALLMODE=`"FilesOnlyMode`""
)
#Check for Drive D
if(gwmi win32_volume -Filter "DriveType=3 AND DriveLetter='D:'"){
Write-Host "D-Drive found. Installing on D"
$Args +="/INSTANCEDIR=`"D:\Programme\SQL2008R2\INSTANCE_SQL2008R2`""
}
#Do Installing
Write-Host "Using the folling Parameter for installing ..."
$Args | %{ Write-Host $_ }
Start-Process -Wait -FilePath $Installer -ArgumentList $Args
#Changing back to swiss regional settings
if($useGermanVersion){ Start-Process -Wait -ArgumentList @("/c", "\\DOS-Scripts\change_locale_de-CH.bat") -FilePath cmd.exe }
Write-Host "Installation finish!"