Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Get installed SQL Server version (for all instances on server) and navigate to the relevant setup folder
# This scripts detecs installed SQL instances through registry and returns version information
$inst = (get-itemproperty 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server').InstalledInstances
foreach ($i in $inst)
$p=(Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL').$i
(Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL').$i
(Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$p\Setup").Edition
(Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$p\Setup").Version
$ver = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$p\Setup").Version
switch ($ver) {
"14.0.3076.1" {"SQL Server 2017 CU14"; break}
"14.0.3006.16" {"SQL Server 2017 CU1"; break}
"14.0.2000.63" {"SQL Server 2017 RTM with Security Update KB4057122"; break}
"14.0.1000.169" {"SQL Server 2017 (vNext) RTM"; break}
"13.0.1601.5" {"SQL Server 2016 RTM"; break}
"12.0.5207.0" {"SQL Server 2014 SP2 with Security Update KB4019093"; break}
"12.2.5000.0" {"SQL Server 2014 SP2"; break}
default {"Unknown Version"; break}
# Part below performs switch to Setup Bootstrap directory of SQL Server installation detected
switch ($ver.Substring(0,2)) {
"14" {cd "C:\Program Files\Microsoft SQL Server\140\Setup Bootstrap\SQL2017"; break}
"13" {cd "C:\Program Files\Microsoft SQL Server\130\Setup Bootstrap\SQLServer2016"; break}
"12" {cd "C:\Program Files\Microsoft SQL Server\120\Setup Bootstrap\SQLServer2014"; break}
"11" {cd "C:\Program Files\Microsoft SQL Server\110\Setup Bootstrap\SQLServer2012"; break}
default {"Unknown Version"; break}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment