kemicza

System.Status: ONLINE

DATE: 2015-12-31 << BACK_TO_LOGS

Recovering a SharePoint 2013 Product Key

"Powershell script for recovering an SharePoint 2013 product key"

Have you ever needed to recover your SharePoint product key? No worries, just use this PowerShell script to retrieve it again ;)

function Get-SP2013ProductKey {
    $map = "BCDFGHJKMPQRTVWXY2346789"
    $value = (get-itemproperty "HKLM:\SOFTWARE\Microsoft\Office\15.0\Registration\{90150000-110D-0000-1000-0000000FF1CE}").digitalproductid
    $baseAddress = 808
    $needsN = ($value[$baseAddress + 14] -shl 3) -and 1;

    $ProductKey = ""
    for ($i = 24; $i -ge 0; $i--) {
        $r = 0
        for ($j = 13; $j -ge 0; $j--) {
            $r = ($r * 256) -bxor $value[$baseAddress + $j]
            $floor = [math]::Floor([double]($r / 24))
            $value[$baseAddress + $j] = $floor
            $r = $r % 24
        }
        $ProductKey = $map[$r] + $ProductKey
    }

    if ($needsN) {
        $firstLetterIndex = 0

        for ($i = 0; $i -lt $ProductKey.Length; $i++) {
            if ($ProductKey[0] -eq $map[$i]) {
                $firstLetterIndex = $i
                break
            }
        }

        $ProductKeyWithN = $ProductKey = $ProductKey.substring(1) # Remove first character
        $ProductKeyWithN = $ProductKeyWithN.SubString(0, $firstLetterIndex) + "N" + $ProductKeyWithN.SubString($firstLetterIndex)
        $ProductKeyWithN = $ProductKeyWithN.SubString(0, 5) + "-" + $ProductKeyWithN.SubString(5, 5) + "-" + $ProductKeyWithN.SubString(10, 5) + "-" + $ProductKeyWithN.SubString(15, 5) + "-" + $ProductKeyWithN.SubString(20, 5)
    }
    $ProductKeyWithN
}
Get-SP2013ProductKey

PAUSE

Stay tuned for more updates on my projects and code snippets!

```