Backup Windows product key in Windows 8 (PowerShell)

Introduction

This PowerShell script sample shows how to get and backup Windows product key in Windows 8 or higher version.

Scenarios

Sometimes a user may want to reinstall operating system, but he does not know the current Windows product key. This script can solve that.

Video

Script

Step 1: Right Click the script and select Run with PowerShell.
 
Step 2: Then it will show messages as the following.
Step 3: Enter Y and press Enter, save Windows product key to a file.
Here are some code snippets for your references.
PowerShell
Edit|Remove
$Keyoffset = 52  
    $isWin8 = [int]($Key[66]/6) -band 1 
    $HF7 = 0xF7 
    $Key[66] = ($Key[66] -band $HF7) -bOr (($isWin8 -band 2) * 4) 
    $i = 24 
    [String]$Chars = "BCDFGHJKMPQRTVWXY2346789"     
    do 
    { 
        $Cur = 0  
        $X = 14 
        Do 
        { 
            $Cur = $Cur * 256     
            $Cur = $Key[$X + $Keyoffset] + $Cur 
            $Key[$X + $Keyoffset] = [math]::Floor([double]($Cur/24)) 
            $Cur = $Cur % 24 
            $X = $X - 1  
        }while($X -ge 0) 
        $i = $i- 1 
        $KeyOutput = $Chars.SubString($Cur,1) + $KeyOutput 
        $last = $Cur 
    }while($i -ge 0)

Prerequisite

Windows 8 or later version