From 4e4551cb9d43407073de073bac16e511a64d909e Mon Sep 17 00:00:00 2001 From: Andreas Jordan <66946165+andreasjordan@users.noreply.github.com> Date: Wed, 7 Jun 2023 13:37:52 +0200 Subject: [PATCH] Get-DbaProductKey - Support SQL Server 2022 (#8952) --- public/Get-DbaProductKey.ps1 | 33 +++------------------------------ 1 file changed, 3 insertions(+), 30 deletions(-) diff --git a/public/Get-DbaProductKey.ps1 b/public/Get-DbaProductKey.ps1 index b39f59c857..55ad5a2923 100644 --- a/public/Get-DbaProductKey.ps1 +++ b/public/Get-DbaProductKey.ps1 @@ -109,7 +109,6 @@ function Get-DbaProductKey { switch ($versionMajor) { 9 { - $sqlversion = "SQL Server 2005 $servicePack" $findkeys = $reg.OpenSubKey("$($instanceReg.Path)\ProductID", $false) foreach ($findkey in $findkeys.GetValueNames()) { if ($findkey -like "DigitalProductID*") { @@ -118,34 +117,10 @@ function Get-DbaProductKey { } } 10 { - $sqlversion = "SQL Server 2008 $servicePack" - if ($server.VersionMinor -eq 50) { - $sqlversion = "SQL Server 2008 R2 $servicePack" - } $key = @("$($instanceReg.Path)\Setup\DigitalProductID") } - 11 { - $key = @("$($instanceReg.Path)\Setup\DigitalProductID", "$($instanceReg.Path)\ClientSetup\DigitalProductID") - $sqlversion = "SQL Server 2012 $servicePack" - } - 12 { - $key = @("$($instanceReg.Path)\Setup\DigitalProductID", "$($instanceReg.Path)\ClientSetup\DigitalProductID") - $sqlversion = "SQL Server 2014 $servicePack" - } - 13 { - $key = @("$($instanceReg.Path)\Setup\DigitalProductID", "$($instanceReg.Path)\ClientSetup\DigitalProductID") - $sqlversion = "SQL Server 2016 $servicePack" - } - 14 { - $key = @("$($instanceReg.Path)\Setup\DigitalProductID", "$($instanceReg.Path)\ClientSetup\DigitalProductID") - $sqlversion = "SQL Server 2017 $servicePack" - } - 15 { - $key = @("$($instanceReg.Path)\Setup\DigitalProductID", "$($instanceReg.Path)\ClientSetup\DigitalProductID") - $sqlversion = "SQL Server 2019 $servicePack" - } default { - Stop-Function -Message "SQL version not currently supported." -Continue + $key = @("$($instanceReg.Path)\Setup\DigitalProductID", "$($instanceReg.Path)\ClientSetup\DigitalProductID") } } if ($edition -notlike "*Express*") { @@ -175,8 +150,7 @@ function Get-DbaProductKey { } [pscustomobject]@{ - Version = $sqlversion - Key = $sqlkey + Key = $sqlkey } $reg.Close() } @@ -202,7 +176,6 @@ function Get-DbaProductKey { Stop-Function -Message "Failure" -Category ConnectionError -ErrorRecord $_ -Target $instanceReg.SqlInstance -Continue } - $servicePack = $server.ProductLevel $versionMajor = $server.VersionMajor Write-Message -Level Debug -Message "$instance $instanceName version is $($server.VersionMajor)" @@ -216,7 +189,7 @@ function Get-DbaProductKey { ComputerName = $server.ComputerName InstanceName = $server.ServiceName SqlInstance = $server.DomainInstanceName - Version = $results.Version + Version = $server.GetSqlServerVersionName() Edition = $server.Edition Key = $results.Key }