Correlate SQL Server version # to name

Solution 1:

You just need a switch (with a regex lookup) added to handle the "mapping" between version and "display" version (as you want it):

$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
     $v = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$p\Setup").Version
     $e = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$p\Setup").Edition

     $mv = switch -Regex ($v) {
        '^8' { 'SQL Server 2000'; Break}
        '^9' { 'SQL Server 2005'; Break }
        '^10.0' { 'SQL Server 2008'; Break }
        '^10.5' { 'SQL Server 2008 R2'; Break }
        '^11' { 'SQL Server 2012'; Break }
        '^12' { 'SQL Server 2014'; Break }
        '^13' { 'SQL Server 2016'; Break }    
        '^14' { 'SQL Server 2017'; Break } 
        '^15' { 'SQL Server 2019'; Break } 
        default { "Unknown SQL Server Version" }
    }

    Write-Host $mv
    write-Host $e
    write-Host $p
}