Skip to content

Instantly share code, notes, and snippets.

@Laim
Last active May 7, 2021 17:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Laim/a14c90257d74f6a0678aac59e66ea470 to your computer and use it in GitHub Desktop.
Save Laim/a14c90257d74f6a0678aac59e66ea470 to your computer and use it in GitHub Desktop.
PowerShell, .NET and SQL Instance Versions in PowerShell
# START : Get SQL Instance Version #
cls # prevents the script itself from echoing out into ISE
"---------------------------------------------------------------------"
$inst = (get-itemproperty 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server').InstalledInstances # Gets the installed SQL instances
$sqlInstanceCount = 0; # loop for the foreach
foreach ($i in $inst)
{
$sqlInstanceCount = $sqlInstanceCount + 1;
$p = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL').$i
"Instance " + $sqlInstanceCount + " SQL Edition: " + (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$p\Setup").Edition
"Instance " + $sqlInstanceCount + " SQL Version: " + (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$p\Setup").Version
}
# END : Get SQL Instance Versions #
"---------------------------------------------------------------------"
# START : Powershell Version #
"Highest PS Ver. Installed: " + (Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine -Name 'PowerShellVersion').PowerShellVersion
# END : PowerShell Version #
"---------------------------------------------------------------------"
# START : .NET Framework Version #
"Highest .NET Fwrk Ver. Installed: " + ([Runtime.InteropServices.RuntimeInformation]::FrameworkDescription -replace '^.[^\d.]*','')
# END : .NET Framework Version #
"---------------------------------------------------------------------"
# START : This can be removed #
"Script Version: 1.1"
"Script Date: 07-May-2021"
"Script Location: https://gist.github.com/Laim/a14c90257d74f6a0678aac59e66ea470"
"---------------------------------------------------------------------"
""
# END : This can be removed #
@Laim
Copy link
Author

Laim commented May 7, 2021

Example output

Example Output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment