4/30/2014 - 1:52 PM

Powershell Installation Scripts

Powershell Installation Scripts

   Install SQL2008R2 Server
   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
   Install-SQL2008R2.ps1 -installOnly SQLEngine -useGerman
    File Name   : Install-SQL2008R2.ps1
    Author      : Robert Rajakone 
    Date        : 05. September 2013    

	[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.equals("SQLEngine") ){
        $Features +="SQLEngine"
        $Features +="FullText"

    if($installOnly.equals("ManagementStudio") ){
        $Features +="SSMS"
        $Features +="SSMS"
        $Features +="RS"
        $Features +="SQLEngine"
        $Features +="FullText"

$FeatureList = $Features -join ","
$Args = @(

#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!"