SQL Server – Retrieve Product Key from an existing installation

SQL Server - Recuperare il Product Key da una installazione esistente

Sometimes you’ll need to retrieve your SQL Server Product Key from an existing installation on your Client or Server machine: the most common scenario takes place when you have an old Server to move or relocate and no one around you seem to remember where the license are… or if you’ve simply lost the Service Key post-it.

Luckily enough, you can easily get this information back thanks to this neat PowerShell script made by Jacob Bindslet:

The script works with any SQL Server edition & version starting from 2005: SQL Server 2005, SQL Server 2008 and SQL Server 2008 R2. Pay close attention, though, if you’re using Sql Server 2012 or Sql Server 2014 you’ll have to make some small modifications to that code.

For Sql Server 2012 you need to replace two lines of code. In details, replace line 5 with the following line:

And also replace line 16 with the following line (thanks to gprkns for pointing it out):

You can also take a look of the complete script code for Sql Server 2012 at the following link.

For Sql Server 2014, Microsoft moved the     node to the actual instance name in the registry, so you will need to replace line 5 with something similar to the following (depending on your installation):

All you have to do in order to execute this script is to perform these actions:

  • Launch a PowerShell prompt (Start > Run, then type powershell and press ENTER.
  • Copy the above function text and past it directly inside the prompt area.
  • Press ENTER a couple times, just to be sure you’re back to the prompt.
  • Type GetSqlServerProductKey, then press ENTER.

If everything has been done like it should you’ll be able to see the following informations:

sql-server-2008-retrieve-product-key

As you can see there’s a lot of stuff regarding your SQL Server installation, most of them you should know already, the latter being the Product Key.

That’s all for now: happy recover!

About Ryan

IT Project Manager, Web Interface Architect and Lead Developer for many high-traffic web sites & services hosted in Italy and Europe. Since 2010 it's also a lead designer for many App and games for Android, iOS and Windows Phone mobile devices for a number of italian companies. Microsoft MVP for Development Technologies since 2018.

View all posts by Ryan

10 Comments on “SQL Server – Retrieve Product Key from an existing installation”

  1. I love the idea. I need this to work. But I’m getting an error when I run the function script. Any idea why? Here is the error. Same result on a Windows Server 2008 R2 and 2012 R2 machine. Both have SQL Server 2012 installed upon them.

    Cannot index into a null array.
    At line:23 char:17
    + $binArray[$j] = [math]::truncate($k / 24)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

    Computer : .

    OSCaption : Microsoft Windows Server 2008 R2 Standard
    OSArch : 64-bit
    SQLver :
    SQLedition :
    ProductKey : BBBBB-BBBBB-BBBBB-BBBBB-BBBBB

    1. I gave this a try on a Windows Server 2008 R2 that was hosting SQL Server 2008 R2, and viola! It worked. But your caveat emptor regarding SQL Server 2014 must also apply to SQL Server 2012? In other words, the value for ‘$regPath = “SOFTWAREMicrosoftMicrosoft SQL ServerMSSQL11.[YOUR SQL INSTANCE NAME]Setup” ‘ needs to be changed in the function? But I’m still getting the error, even though I opened up regedit and confirmed the path is as shown. Any other ideas?

      1. You were on the right track, but for Sql Server 2012 you still have to use the old-format regPath. I updated the post with the proper mods to apply in order for it to work with Sql Server 2012. Please let me know if it solves your issue.

        1. Changing the regkey is not enough by itself. (Sorry no SQL 2014 to test that mod.) I did a little more Googling and found a working version of your script modified by Xian Wang for SQL 2012. Here is a link to his working version of the same PowerShell function: https://xzwang.wordpress.com/2013/06/22/retreiving-sql-server-2012-product-key-from-the-registry/

          1. You’re right, the binArray has to be changed aswell. I updated the post mentioning your suggestion and including the link to Xian Wang’s blog. Thanks for your valuable feedback! 🙂

  2. hi wonder if you can help
    ive a licence number but no product key for SQL SVR STD EDTN 2014 SNGL OLP NL
    how do i enter licence number

    ——————————

    There are validation errors on this page. Click OK to close this dialog box. Review errors at the bottom of the setup page, then provide valid parameters or click Help for more information.

    ——————————
    BUTTONS:

    OK
    ——————————

  3. Pingback: Retrieving the SQL Server License Key – SQLAndy
  4. IT SYS ADMINS!!! This script DOES NOT WORK! I’ve already wasted a few days on it. https://gallery.technet.microsoft.com/scriptcenter/Get-SQL-Server-Product-4b5bf4f8/view/Discussions#content Doesn’t work either! Figured I’d save yall some time. I still have no working solution.

  5. Pingback: Microsoft SQL Server How To: Get Product Key Using Powershell - Kaizenlog.com
  6. I get the following error: Cannot index into a null array.
    At line:23 Char:27
    $binArray[ <<<< $j] = [math]::truncate($k / 24)

    Help!

  7. I’m trying this on Windows Server 2008 R2 running SQL Server 2008 R2 and I get the following error:
    Cannot index into a null array.
    At line:23 char:27
    + $binArray[$j] = [math]::truncate($k / 24)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (1:Int32) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

    Please help!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.