Skip to content
All gists
Back to GitHub
Sign in
Sign up
Sign in
Sign up
{{ message }}
Instantly share code, notes, and snippets.
mikerodionov
/
Get_SQL_version_and_navigate_to_setup_folder.ps1
Last active
March 16, 2021 17:00
Star
1
Fork
0
Star
Code
Revisions
4
Stars
1
Embed
What would you like to do?
Embed
Embed this gist in your website.
Share
Copy sharable link for this gist.
Clone via HTTPS
Clone with Git or checkout with SVN using the repository’s web address.
Learn more about clone URLs
Download ZIP
Get installed SQL Server version (for all instances on server) and navigate to the relevant setup folder
Raw
Get_SQL_version_and_navigate_to_setup_folder.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
# 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
You can’t perform that action at this time.
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.