How to get SQL Server product key from installation media

You can easily just run the SQL Server installation and get the product key that is provided on the "Product Key" page but it is easier to just grab the key directly from the installation disc/image.

Mount your installation media and open the file <Drive>:\x64\DefaultSetup.ini and the product key will be the value of the PID key:

;SQL Server 2019 Configuration File
[OPTIONS]
PID="XXXXX-XXXXX-XXXXX-XXXXX-XXXXX"

If SQL Server is already installed and you want the product key for the installed SQL Server instance, you can use the Get-SqlServerKeys.ps1 PowerShell script. I've had to update it for SQL Server 2019, so you can get a copy of that script below.

Get-SqlServerKeys with support for SQL Server 2019
Get-SqlServerKeys with support for SQL Server 2019 - Get-SqlServerKeys.ps1