Tuesday 17 January 2012

Find SQL Server 2008 R2 Product Key from Powershell


Dear All,

Was struggling a bit to find SQL server 2008 R2 key, across multiple search i came through a powershell script which was very helpful in finding the key

Here it goes - Open Poweshell and copy paste this script

function Get-SQLserverKey {
    ## function to retrieve the license key of a SQL 2008 Server.
     param ($targets = ".")
    $hklm = 2147483650
    $regPath = "SOFTWARE\Microsoft\Microsoft SQL Server\100\Tools\Setup"
    $regValue1 = "DigitalProductId"
    $regValue2 = "PatchLevel"
    $regValue3 = "Edition"
    Foreach ($target in $targets) {
        $productKey = $null
        $win32os = $null
        $wmi = [WMIClass]"\\$target\root\default:stdRegProv"
        $data = $wmi.GetBinaryValue($hklm,$regPath,$regValue1)
        [string]$SQLver = $wmi.GetstringValue($hklm,$regPath,$regValue2).svalue
        [string]$SQLedition = $wmi.GetstringValue($hklm,$regPath,$regValue3).svalue
        $binArray = ($data.uValue)[52..66]
        $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"
        ## decrypt base24 encoded binary data
        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
            If (($i % 5 -eq 0) -and ($i -ne 0)) {
                $productKey = "-" + $productKey
            }
        }
        $win32os = Get-WmiObject Win32_OperatingSystem -computer $target
        $obj = New-Object Object
        $obj | Add-Member Noteproperty Computer -value $target
        $obj | Add-Member Noteproperty OSCaption -value $win32os.Caption
        $obj | Add-Member Noteproperty OSArch -value $win32os.OSArchitecture
        $obj | Add-Member Noteproperty SQLver -value $SQLver
        $obj | Add-Member Noteproperty SQLedition -value $SQLedition
        $obj | Add-Member Noteproperty ProductKey -value $productkey
        $obj
    }
}


After pasting the script just call the function as shown below and enter


Get-SQLserverKey - This will get you Key of the local PC


Output would look like the below


Computer : comp.domain.com

OSCaption : Microsoft Windows Server 2008 R2 Enterprise

OSArch : 64-bit

SQLver : 10.50.1600.1

SQLedition : Enterprise Edition

ProductKey : XXXXX-XXXXX-XXXXX-XXXXX-XXXXX


PS note: The above script works against SQL Server 2008 and SQL Server 2008 R2, NOT SQL 2005.


Happy Getting Key...


Regards

Sandeep patil


Thanks to : Jakob Bindslet

31 comments:

  1. Thnx! Works great

    ReplyDelete
    Replies

    1. windows 7 home premium valid product key , windows 7 ultimate sp1 key , windows 10 product key , sql server 2008 r2 enterprise crack , windows key 7 ultimate , free windows product key for windows 7 , installer of windows xp professional , buy windows 10 product key , lTyv0y

      Delete
    2. genuine version of norton antivirus , product key for windows 7 ultimate free , buy windows 10 activator discount , windows 10 activation 0xd0000272 , windows 10 serial key install , update windows 7 ultimate sp1key , windows server 2012 r2 free , windows 10 serial key y , srBp8c

      office 2016 registry purchase

      cheap office 2013 key

      microsoft visio professional 2016 order

      cheap windows 10 product key sale

      Delete
    3. genuine version of norton antivirus , product key for windows 7 ultimate free , buy windows 10 activator discount , windows 10 activation 0xd0000272 , windows 10 serial key install , update windows 7 ultimate sp1key , windows server 2012 r2 free , windows 10 serial key y , srBp8c

      office 2016 registry purchase

      cheap office 2013 key

      microsoft visio professional 2016 order

      cheap windows 10 product key sale

      Delete
    4. Still works for SQL Server 2008R2! Thank you!!!!!!

      Delete
  2. i copied and paste the code to powershell session.

    PS E:\downloads> Get-SQLserverKey
    Cannot index into a null array.
    At line:17 char:36
    + $binArray = ($data.uValue)[ <<<< 52..66]
    + CategoryInfo : InvalidOperation: (System.Object[]:Object[]) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

    ReplyDelete
  3. Wow... this is more than great! I have been searching for this and installed this and that. None of those worked, but your script worked like breeze. Thank you so much!

    ReplyDelete
  4. This is awesome! Thanks for this! You are the man!

    ReplyDelete
  5. Hi all, I've modified this script to work with Sql Server 2012 as well. Please see this post:

    http://xzwang.wordpress.com/2013/06/20/oracle-ole-db-performance/

    ReplyDelete
  6. SUPER AWESOME! Thank you , worked like a charm

    ReplyDelete
  7. Ok,thanks .My friend recommended strongly http://www.vanskeys.com to me, and i visited the site. it looks good.

    ReplyDelete
  8. Thank you.If you want cheaper and genuine from this site:www.finmde.com.It's good choice.

    ReplyDelete
  9. Hey,guys,If you want some free HTTP download links for all the product keys. you can visit this web: www.aakeys.com,It's good site, They can give me cheaper price. If someone is interested,highly recommend.

    ReplyDelete
  10. Thanks very much for sharing,I recommed you a site:http://www.esplaieltricicle.org/fotos/File/de/key.asp?topic=Adobe-Acrobat-9-Pro-Extended-kaufen, it's very useful and cheap,Hope it works for you.

    ReplyDelete
  11. Hey, I recommend you to choose http://www.galerie-kaplicka.cz/UserFiles/de/key.asp?topic=Adobe-Acrobat-9-Pro-Extended-kaufen,They have the lowest prices I have found and the service is excellent.

    ReplyDelete
  12. I suggest you go www.frekeys.com. Yesterday I purchased from their website. Every time I was surprised price and customer service. I recommend this site to many friends. Will prove my words

    ReplyDelete
  13. Windows10Keysale.com


    of course, the best place to buy a key is ms. i purchased years from ms online store. however, this time, i'd like to share one special experience on Windows10Keysale.com .
    i visit my forum everyday. one day, i found a piece of recommendation from another guy. so i visited this site.
    at the beginning, i'm quite skeptical at them. the price is too low.
    then i sent many questions to them.
    out of my expectation, they replied to me very soon. each question was answered.
    at that time, i planned to try the new Office 2007 key.
    long story short, i purchased a key from them, received it and download links(32bit&64bit) in about one hour. i need 64. and, more important, the key works at the first try.
    i sent much feedback to them. in one word, i'm very satisfied with this purchase, and i think, i should pass words to you.

    Windows10Keysale.com

    ReplyDelete
  14. if you need genuine office you can try this link, my office got here and works well,strongly recommend you, it is brilliant www.lightonthekey.com
    wish you good luck

    ReplyDelete
  15. You guys can find some 100% working Dynamics CRM Product Keys here: www.gankings.com.

    ReplyDelete
  16. Thanks for sharing! For Windows/Office product keys any editions, you can find some great ones here: www.motionkeys.com.

    ReplyDelete
  17. Got the product key recommended by my friend, perfectly used! Share with you: www.cdekey.com.

    ReplyDelete
  18. You can buy cheap product license keys from ODosta Store which is legit site as I recently bought Windows 10 pro for my PC, Which is working well. They accept PayPal and bitcoin payment and offer lifetime warranty.
    I'll recommend it as their customer support service is very good.

    ReplyDelete
  19. If someone who wanna key go site www.softkeyhome.com to got. My key got here and after i used is works great. 100% genuine it provide.

    ReplyDelete

  20. WINDOWS 10 PRODUCT KEY

    Thanks to the online product key vendor http://www.keysforvip.com/ , I get the legal copy of the product key in the first time. Now, my Windows 10 key system brings to me a good user experience. Any such problem, go this online site for help. You certainly will get your problem solved.

    WINDOWS 10 PRODUCT KEY

    ReplyDelete
  21. Great post, you have pointed out some excellent points, I as well believe this is a very superb website.
    buy windows 10 pro activation key

    ReplyDelete