Installing SQL 2014

Installing SQL 2014 isn’t quite as different as installing SQL Server 2012. Sure there are some minor UI changes when installing SQL, but it’s all the same. In order for SharePoint to work with SQL, we only need the database engine. I don’t want to click my way through the setup every time I need to install SQL server. I tried to work with the SQL configuration file, but somehow that didn’t worked for me. I found an PowerShell script for installing SQL server 2012 and it works great, I wanted to see if there were no changes in installing SQL. So trying the PowerShell script and installing SQL 2014 was an easy task.

I know what you’re thinking… what kind of PowerShell script did he use, well here’s the code:

[code language=”PowerShell”]
Function Install-Sql
{
param
(
[Parameter(Position=0,Mandatory=$false)][string] $Path,
[Parameter(Position=1,Mandatory=$false)][string] $InstanceName = "MSSQLSERVER",
[Parameter(Position=2,Mandatory=$false)][string] $ServiceAccount,
[Parameter(Position=3,Mandatory=$false)][string] $Userdb,
[Parameter(Position=4,Mandatory=$false)][string] $Userdblog,
[Parameter(Position=5,Mandatory=$false)][string] $Tempdb,
[Parameter(Position=6,Mandatory=$false)][string] $Tempdblog,
[Parameter(Position=7,Mandatory=$false)][string] $ServicePassword,
[Parameter(Position=8,Mandatory=$false)][string] $AgentServiceAccount,
[Parameter(Position=9,Mandatory=$false)][string] $AgentServicePassword,
[Parameter(Position=10,Mandatory=$false)][string] $SaPassword,
[Parameter(Position=11,Mandatory=$false)][string] $LicenseKey,
[Parameter(Position=12,Mandatory=$false)][string] $SqlCollation = "LATIN1_General_CI_AS_KS_WS",
[Parameter(Position=13,Mandatory=$false)][switch] $NoTcp,
[Parameter(Position=14,Mandatory=$false)][switch] $NoNamedPipes,
[Parameter(Position=15,Mandatory=$false)][switch] $Features
)

#Build the setup command using the install mode
if ($Path -eq $null -or $Path -eq "") {
#No path means that the setup is in the same folder
$command = ‘setup.exe /Action="Install"’
} else {
#Ensure that the path ends with a backslash
if(!$Path.EndsWith("\"))
{
$Path += "\"
}

$command = $path + ‘setup.exe /Action="Install"’
}

#Accept the license agreement – required for command line installs
$command += ‘ /IACCEPTSQLSERVERLICENSETERMS’

#Use the QuietSimple mode (progress bar, but not interactive)
$command += ‘ /QS’

#Set the features to be installed
if ($Features -ne $null -and $Features -ne "") {
$command += ‘ /FEATURES=SQLENGINE,ADV_SSMS’
}

#Set the Instance Name
$command += (‘ /INSTANCENAME="{0}"’ -f $InstanceName)

#Set the License Key only if a value was provided, otherwise install Evaluation edition
if ($LicenseKey -ne $null -and $LicenseKey -ne "") {
$command += (‘ /PID="{0}"’ -f $LicenseKey)
}

#Set the database directory
if ($Userdb -ne $null -ne "") {
$command += (‘ /SQLUSERDBDIR="{0}"’ -f $Userdb)
}

#Set the database log directory
if ($Userdblog -ne $null -ne "") {
$command += (‘ /SQLUSERDBLOGDIR="{0}"’ -f $Userdblog)
}

#Set the tempdb directory
if ($Tempdb -ne $null -ne "") {
$command += (‘ /SQLTEMPDBDIR="{0}"’ -f $Tempdb)
}

#Set the tempdb log directory
if ($Tempdblog -ne $null -ne "") {
$command += (‘ /SQLTEMPDBLOGDIR="{0}"’ -f $Tempdblog)
}

#Check to see if a service account was specified
if ($ServiceAccount -ne $null -and $ServiceAccount -ne "") {
#Set the database engine service account
$command += (‘ /SQLSVCACCOUNT="{0}" /SQLSVCPASSWORD="{1}" /SQLSVCSTARTUPTYPE="Automatic"’ -f $ServiceAccount, $ServicePassword)
} else {
#Set the database engine service account to Local System
$command += ‘ /SQLSVCACCOUNT="NT AUTHORITY\SYSTEM" /SQLSVCSTARTUPTYPE="Automatic"’
}

#Check to see if a service account was specified
if ($AgentServiceAccount -ne $null -and $AgentServiceAccount -ne "") {
#Set the SQL Agent service account
$command += (‘ /AGTSVCACCOUNT="{0}" /AGTSVCPASSWORD="{1}" /AGTSVCSTARTUPTYPE="Automatic"’ -f $ServiceAccount, $ServicePassword)
} else {
#Set the SQL Agent service account to Local System
$command += ‘ /AGTSVCACCOUNT="NT AUTHORITY\SYSTEM" /AGTSVCSTARTUPTYPE="Automatic"’
}

#Set the server in SQL authentication mode if an SA password was provided
if ($SaPassword -ne $null -and $SaPassword -ne "") {
$command += (‘ /SECURITYMODE="SQL" /SAPWD="{0}"’ -f $SaPassword)
}

#Add current user as SysAdmin
$command += (‘ /SQLSYSADMINACCOUNTS="{0}"’ -f [Security.Principal.WindowsIdentity]::GetCurrent().Name)

#Set the database collation
$command += (‘ /SQLCOLLATION="{0}"’ -f $SqlCollation)

#Enable/Disable the TCP Protocol
if ($NoTcp) {
$command += ‘ /TCPENABLED="0"’
} else {
$command += ‘ /TCPENABLED="1"’
}

#Enable/Disable the Named Pipes Protocol
if ($NoNamedPipes) {
$command += ‘ /NPENABLED="0"’
} else {
$command += ‘ /NPENABLED="1"’
}

if ($PSBoundParameters[‘Debug’]) {
Write-Output $command
} else {
Invoke-Expression $command
}
}

Import-Module ServerManager

Write-Host "Installing .NET Framework Feature…" -NoNewline
If ((Get-WMIObject win32_OperatingSystem).Version -match "6.1.76") {
if (-not (Get-WindowsFeature NET-Framework).Installed) {
Add-WindowsFeature NET-Framework | Out-Null

Write-Host -f Green " – Done!"
} else {
Write-Host -f Gray " – Already Installed"
}
} elseIf ((Get-WMIObject win32_OperatingSystem).Version -match "6.2.92") {
if (-not (Get-WindowsFeature NET-Framework-Core).Installed) {
Add-WindowsFeature NET-Framework-Core | Out-Null

Write-Host -f Green " – Done!"
} else {
Write-Host -f Gray " – Already Installed"
}
}

Write-Host

Install-Sql -Path D:\ -ServiceAccount "domain\serviceaccount" -ServicePassword "Password"
[/code]

 

Comments

Leave a Reply

Discover more from Something Technical

Subscribe now to keep reading and get access to the full archive.

Continue reading