Get SQL Server Product Keys for Local and Remote Servers using PowerShell

I just released a new PowerShell script, Get-SQLServerKeys.ps1. The script works works with several versions of SQL Server (2005-2014), and can use Central Management Server, a text file, or just a string of servers as input.

PowerShell x64
PS C:\github\sqlmigration> .\Get-SQLServerKeys.ps1 winxp, sqlservera, sqlserver, sqlcluster

SQL Instance            SQL Version               SQL Edition                                   Product Key
-----------            ----------               ----------                                   ----------
winxp\SQL2K5            SQL Server 2005 SP4       Developer Edition                              XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
sqlservera              SQL Server 2014 RTM       Enterprise Edition: Core-based                 XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
sqlservera\SQLEXPRESS   SQL Server 2008 SP3       Express Edition (64-bit)                       SQL Server Express Edition
sqlcluster              SQL Server 2014 RTM       Standard Edition (64-bit)                      XXXXX-XXXXX-XXXXX-XXXXX-XXXXX

PS C:\github\sqlmigration> .\Get-SQLServerKeys.ps1 -CentralMgmtServer sqlserver -verbose
VERBOSE: Attempting to connect to sqlservera
VERBOSE: Attempting to connect to sqlservera\SQLEXPRESS
VERBOSE: Attempting to connect to win2k8
VERBOSE: Attempting to connect to win2k8\SQL2K8S
VERBOSE: Attempting to connect to winxp\SQL2K5
VERBOSE: Attempting to connect to sqlserver

SQL Instance            SQL Version               SQL Edition                                   Product Key
-----------            ----------               ----------                                   ----------
sqlservera              SQL Server 2014 RTM       Enterprise Edition: Core-based                 XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
sqlservera\SQLEXPRESS   SQL Server 2008 SP3       Express Edition (64-bit)                       SQL Server Express Edition
win2k8                  SQL Server 2008 R2 RTM    Developer Edition                              XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
win2k8\SQL2K8S          SQL Server 2008 SP1       Standard Edition (64-bit)                      XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
winxp\SQL2K5            SQL Server 2005 SP4       Developer Edition                              XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
sqlserver               SQL Server 2014 RTM       Enterprise Edition: Core-based                 XXXXX-XXXXX-XXXXX-XXXXX-XXXXX

Like many of the Windows Key scripts available, this one relies on Remote Registry being enabled. However, if you've disabled this service, you can run Get-SQLServerKeys.ps1 on the SQL Server itself and all keys will be extracted for all local instances by accessing the registry directly.

Windows PowerShell
PS C:\scripts> .\Get-SQLServerKeys.ps1

SQL Instance            SQL Version            SQL Edition                          Product Key
-----------            ----------            ----------                          ----------
SQLSERVERA              SQL Server 2012 SP1    Enterprise Edition: Core-based       XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
SQLSERVERA\SQLEXPRESS   SQL Server 2008 SP3    Express Edition (64-bit)             SQL Server Express Edition

PS C:\scripts>

Thanks goes out to Jakob Bindslet for providing the key decode function.

Get-SQLServerKeys.ps1 is one of several scripts that help DBA's migrate SQL Servers. Check out my sqlmigration repository on GitHub for more scripts.

Update 2025: The original TechNet Gallery link above now points to an archived copy. The old sqlmigration GitHub repository has since been retired. For a modern, maintained approach, see dbatools’ Get-DbaProductKey, which retrieves Windows and SQL Server product keys locally or remotely.