This is copied from a daily email I get from powershell.com
Getting Windows Product Key
Ever wanted to read out the Windows license key? In the Windows Registry, this key is present, but it is stored as a digital ID. To convert it back to the license key used to originally license the product, try this function. It uses some serious math:
function Get-ProductKey {
$map="BCDFGHJKMPQRTVWXY2346789"
$value = (get-itemproperty "HKLM:SOFTWAREMicrosoftWindows NTCurrentVersion").digitalproductid[0x34..0x42]
$ProductKey = ""
for ($i = 24; $i -ge 0; $i—) {
$r = 0
for ($j = 14; $j -ge 0; $j—) {
$r = ($r * 256) -bxor $value[$j]
$value[$j] = [math]::Floor([double]($r/24))
$r = $r % 24
}
$ProductKey = $map[$r] + $ProductKey
if (($i % 5) -eq 0 -and $i -ne 0) {
$ProductKey = "-" + $ProductKey
}
}
$ProductKey
}
http://powershell.com/cs/blogs/tips/archive/2012/04/30/getting-windows-product-key.aspx
It would be great if you could convert the source code to an executable product key recovery program, such as “KeyFinder Plus”.
I was unable to get your code to work above.
I am on a SharePoint 2010 system that uses powershell v2.
When I copy and pasted the code into a file and attempted to run it, I got the error:
PS C:Userssa_spfarmDocumentsWindowsPowerShell> ./get-productkey.ps1
– : You must provide a value expression on the right-hand side of the ‘-‘ operator.
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : ExpectedValueExpression
I _think_ the problem is the expression $i- – should that not be $i– ?
Unfortunately, when I try to use that, then I get the error
[ : Cannot index into a null array.
At C:Userssa_spfarmDocumentsWindowsPowerShellget-productkey.ps1:10 char:16
+ $value[ <<<< $j] = [math]::Floor([double]($r/24))
+ CategoryInfo : InvalidOperation: (5:Int32) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
[ : Cannot index into a null array.
At C:Userssa_spfarmDocumentsWindowsPowerShellget-productkey.ps1:9 char:38
+ $r = ($r * 256) -bxor $value[ <<<< $j]
+ CategoryInfo : InvalidOperation: (4:Int32) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
That seems to indicate that the get-ItemProperty returned a null value.
Obviously there is a license key on the farm since we are using it.
So I don't understand what has to be done. Could it be that there is something wrong with the registry string?
This is for finding the windows OS key, not a SP farm key.
Hello Collin,
do you have any idea where and/or how we can read out the MAK key on a Server 2008R2 and Server 2012R2?
Your script works fine for all “normal” keys, but I cannot get the correct MAK key by running your script on these servers.
The reason why I need to read out these keys is because of auditing: we have to verify which servers are installed by which key and compare it then to our database.
I found somewhere in Google that the MAK (SPLA) keys, are not saved in the registry? Is that correct?
Another post I found, “Just Change the “DigitalProductId” to “DigitalProductId4″ and it will work.” Any idea?
We don’t have an answer yet.
Thanks in advance!
Kind Reagards,
Dirk
Vista, Windows 7, 8, 10, Windows Server 2008, and 2012 operating systems using corporate MAK (Multiple Activation Keys) or VLK (Volume License Keys) cannot be recovered since they are not stored in the system.
Some key finder programs show the key as “BBBBB-BBBBB-BBBBB-BBBBB”. Belarc is one popular example.
Use Kmspico-auto to reset Key
Vista/Windows Server 2008 and above using a corporate MAK (Multiple Activation Keys) or VLK (Volume License Keys) cannot be recovered since the key is not stored in the system. Once it activates, its gone. If you lose your activation, change allot of hardware, you will need to have your key handy.
Hi. Thanks for posting this!
It looks like at some point the blogging software might have mutilated the code? There are no backslashes in the key path.