There are several situations in which you may need to retrieve the SQL Server Product Key from a Windows Server:

1. Reinstalling SQL Server: If you need to reinstall SQL Server on the same server, you will need the Product Key to complete the installation process.

2. Upgrading the SQL Server Edition: If you want to upgrade the edition of SQL Server that you are using, you will need the Product Key for the upgraded edition.

3. Troubleshooting Licensing Issues: If you are experiencing licensing issues with SQL Server, you may need to contact Microsoft and provide the Product Key to receive assistance.

4. Moving SQL Server to a New Server: If you want to move an instance of SQL Server to a new server, you will need the Product Key to activate the software on the new server.

5. Restoring from a Backup: If you are restoring a backup of an instance of SQL Server, you may need the Product Key to reactivate the software.

How to recover SQL Server Product Key with PowerShell

Go directly on windows server and create this powershell, then you can execute it, and return the product key of your SQL Server

function powershellsqlserver {
$fromReg = 1

if ($fromReg -eq 1) {
$localmachine = [Microsoft.Win32.RegistryHive]::LocalMachine
$defaultview = [Microsoft.Win32.RegistryView]::Default
$reg = [Microsoft.Win32.RegistryKey]::OpenBaseKey($localmachine, $defaultview)
$key = "SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL15.MSSQLSERVER\Setup"
$encodedData = $reg.OpenSubKey($key).GetValue(“DigitalProductID”)
$reg.Close()
}
else {
$encodedData = 27,17,0,0,0,0,172,132,0,167,211,98,242,243,11,0
}

try {
$binArray = ($encodedData)[0..66]
$productKey = $null

$charsArray = "B","C","D","F","G","H","J","K","M","P","Q","R","T","V","W","X","Y","2","3","4","6","7","8","9"

$isNKey = ([math]::truncate($binArray[14] / 0x6) -band 0x1) -ne 0;
if ($isNKey) {
$binArray[14] = $binArray[14] -band 0xF7
}

$last = 0

for ($i = 24; $i -ge 0; $i--) {
$k = 0
for ($j = 14; $j -ge 0; $j--) {
$k = $k * 256 -bxor $binArray[$j]
$binArray[$j] = [math]::truncate($k / 24)
$k = $k % 24
}
$productKey = $charsArray[$k] + $productKey
$last = $k
}

if ($isNKey) {
$part1 = $productKey.Substring(1, $last)
$part2 = $productKey.Substring(1, $productKey.Length-1)
if ($last -eq 0) {
$productKey = "N" + $part2
}
else {
$productKey = $part2.Insert($part2.IndexOf($part1) + $part1.Length, "N")
}
}

$productKey = $productKey.Insert(20, "-").Insert(15, "-").Insert(10, "-").Insert(5, "-")
} catch {
$productkey = "Cannot decode product key."
}

Write-Host $productKey
}