PowerShell Script : Installing Standalone SQL Server 2012
In this article, I would be sharing a script which I created to Install Standalone SQL Server 2012 on a windows server.
I have pasted the script at the end of this article and I would encourage you to test this script and share your feedback
I came across a situation where I need to install SQL Server manually on a windows machine and installing SQL server manually was quite frustrating for me as at the time of installation the SQL Server performs lots of checks and you need to sit there and accept all those checks. And I was thinking if this installation is so frustrating for me then how much frustrating it will be for the people who do this kind of installation on daily basis and they need to make sure they are according to company standards. So I thought of automating this installation and so I created this script.
This PowerShell script uses one parameter known as Configuration File. You can use the configuration file to deploy SQL Server throughout the enterprise with the same configuration. This configuration file will be required to automate the installation. This SQL Configuration can be generated by following these steps.
- Follow the wizard through to the Ready to Install page. The path to the configuration file is specified in the Ready to Install page in the configuration file path section. See Install SQL Server from the Installation Wizard (Setup).
- Cancel the setup without actually completing the installation, to generate the INI file.
Once you generated the Configuration file you need to make few changes on the parameter present in the configuration file so that you could have truly silent installation and these changes as follows.
- IACCEPTSQLSERVERLICENSETERMS="True"
- ACTION="Install"
- QUIET="True"
- QUIETSIMPLE="False"
- UpdateEnabled="False"
You must be aware that SQL Server 2012 requires the KB article ie KB2919442 and KB2919355 need to be installed on the server as a prerequisite You just need to download this MSU files from this links and need to store it with configuration file the script will automaticall install these KB articles.
KB2919442 : https://www.microsoft.com/en-in/download/details.aspx?id=42153
KB2919355: https://www.microsoft.com/en-in/download/details.aspx?id=42334
After you have downloaded the KB articles you need tp follow these steps for running this script.
1: Create a folder named "SQLServerInstallation" on the inside of the C:\Windows\Temp folder ie the final path should be like this "C:\Windows\Temp\SQLServerInstallation"
2: Copy the KB articles and configuration file which you generated in the above steps to this folder "SQLServerInstallation"
3: Extract the contents of the SQL Server ISO image and copy all those contents to the "SQLServerInstallation" folder.
4: Copy the PowerShell script and store it in a file and name the file as "InstallingStandaloneSQLServer.ps1 " and store this file also in the folder "SQLServerInstallation".
After you completed these steps your "SQLServerInstallation" folder would look like this.
Working of the script
The first thing the script will do is that it will check for the KB articles "KB2919355 & KB 2919442" are installed on the machine or not and if they are installed it will move with the installation of SQL Server on the machine.
If the KB article is not present on the machine then the script will ask if you like to install these KB articles and if you said yes then it will install the KB articles automatically it will reboot the server automatically and will move ahead with the rest of the installation.
That's all folks.
In case we haven’t met before, I’m Thahir. Thank you for reading. I hope you liked this article. :) and would request you to share this article among your friends As this article may be useful for them. Also If you have any suggestions to improve this script please let me know. Also if you have any new ideas or day to day tasks which you think needs to be automated let me know and I will give it a try.
Script
$sourcepath = "C:\Windows\Temp" #Source Path where you will create the folder "SQLServerInstallation"
$childpath = "\sqlserverinstallation" #folder name if you want to change it.
$finalpath = Join-Path -Path $sourcepath -ChildPath $childpath
$ConfigurationFilePath = "$finalpath\ConfigurationFile.INI" #Location of configuration INI file.
$KBArticle = Get-HotFix -Id KB2919355 -ErrorAction SilentlyContinue
if (-not($KBArticle))
{
$kbinstallanswer = Read-Host -Prompt "Do you want to install the KB 2919355 as after installing this KB the server will be reboted 'n If your answer is Yes press Y else press N for no"
if($kbinstallanswer -eq 'y')
{
Write-host "Installing the KB"
Start-Process -FilePath "Wusa.exe" -ArgumentList "$finalpath\Windows8.1-KB2919442-x64.msu /quiet /norestart" -Wait
Start-Process -FilePath "Wusa.exe" -ArgumentList "$finalpath\Windows8.1-KB2919355-x64.msu /quiet /norestart" -Wait
Set-ItemProperty "HKLM:\Software\Microsoft\Windows\CurrentVersion\RunOnce" -Name 'SQLServerInstallation' -Value "c:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -noexit -file C:\scripts\InstallingStandaloneSQLServer.ps1"
Restart-Computer
}
}
else {
Write-host "Moving ahead with the installation"
New-Item -Path "C:\Program Files (x86)\" -ItemType "directory" -Name "Microsoft SQL Server" -Force
New-Item -Path "C:\Program Files (x86)\Microsoft SQL Server\" -Name "DReplayClient" -ItemType "directory" -Force
New-Item -Path "C:\Program Files (x86)\Microsoft SQL Server\DReplayClient\" -Name "ResultDir" -ItemType "Directory" -Force
New-Item -Path "C:\Program Files (x86)\Microsoft SQL Server\DReplayClient\" -Name "WorkingDir" -ItemType "Directory" -Force
Invoke-Expression -Command "C:\Windows\Temp\SQLServerInstallation\Setup.exe /ConfigurationFile=$ConfigurationFilePath"
}
Awesome Thahir