How to Retrieve SQL Server Product Keys


This quick tip will come in handy when you need to find out the product keys for an installed SQL Server if that information was not recorded when it was initially installed.

Please note that this PowerShell module and its corresponding Get-SqlServerKeys command only works for MS SQL Server 2005 – 2014. It is currently not compatible with MS SQL Server 2016.

Here are the steps  you need to carry out from a desktop computer running Windows 7 or above to retrieve the SQL Server product keys.

1 Confirm PowerShell version

2 Download and install PowerShell 3.0 if required

If you have an older PowerShell version (e.g. version 1 or 2), then upgrade it to version 3. To do so, you will need to download and install Windows Management Framework 3.0 which also contains PowerShell 3.0 from this website:

https://www.microsoft.com/en-au/download/details.aspx?id=34595

3 Download the PowerShell module for retrieving the product keys

Once you’ve successfully upgraded to PowerShell version 3, please head over to this website to download the PowerShell module for retrieving SQL Server product keys:

https://gallery.technet.microsoft.com/scriptcenter/Get-SQL-Server-Product-4b5bf4f8/view/Discussions#content

4 Check Execution Policy

Before you can import and execute the PowerShell command to retrieve the SQL Server product keys, you will need to check the desktop computer’s execution policy.

If the execution policy is set to Restricted (which is the default), then temporary set it to Unrestricted. Import the PowerShell module you download in step 3, execute the command to retrieve the SQL Server product keys and then set it back to the default Restricted execution policy, that is:

  PS > Get-ExecutionPolicy
  PS > Set-ExecutionPolicy -ExecutionPolicy Unrestricted
    [Yes] Y

5 Import the PowerShell module for retrieving the product keys

Once the execution policy restriction has been lifted (i.e. temporary set to unrestricted), import the PowerShell module you download in step 3 so that the command Get-SqlServerKeys is available in the current session.

  PS > Import-Module .\Get-SqlServerKeys.psm1
    Run Once [R]

6 Run the Get-SqlServerKeys command to retrieve the product keys

Execute the Get-SqlServerKeys command to retrieve the SQL Server product keys. To retrieve SQL Server product remotely (i.e. those on a remote server), use the Server parameter, i.e.

  PS > Get-SqlServerKeys -Servers <list-of-remote-server-fqdn-or-ip-addresses>

The Servers parameter takes a list of server’s full qualify domain names (or IP addresses). If you’re on the actual server (i.e. not issuing the command from your client desktop computer), then the Servers parameter can be omitted, i.e.

  PS > Get-SqlServerKeys

Here are the commands:

And the returned information:

It will list all the SQL Server instances if there are multiple instances on the server. Please note the above assume you’re running the command from the actual server, and not remotely. If running from a client desktop computer, you will need to add the -Servers parameter and its list of servers names or IP addresses.

7 Set the Execution Policy to Restricted

Once you’re done, please don’t forget to set the execution policy back to the default Restricted.

  PS > Set-ExecutionPolicy -ExecutionPolicy Restricted
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s