title: REG_BINARY to Windows-Key in PowerShell
body: <p>I am trying to extract a "readable" win10-key from a device, where the key is digital.</p>
  
  <p>Meaning :
  <code>(Get-WmiObject -query ‘select * from SoftwareLicensingService’).OA3xOriginalProductKey</code>
  gives no result.</p>
  
  <p>I use <code>reg query HKLM\SOFTWARE\Microsoft\"Windows NT"\CurrentVersion /v DigitalProductId</code> but ofcourse i get the REG_BINARY output.</p>
  
  <p>Anyone has any idea how to convert it to the "normal" win10-key?</p>
  
  <p>Edit: Readable = The normal windows Product-key (normally found on the sticker) for example: <code>9JNB6-GWD4G-JQHC7-*****-*****</code></p>
  
  <p>Edit 2: VBS script that works.</p>
  
  <pre><code>    Const KeyOffset = 52
      Dim isWin10, Maps, i, j, Current, KeyOutput, Last, keypart1, insert
      'Check if OS is Windows 10
      isWin10 = (Key(66) \ 6) And 1
      Key(66) = (Key(66) And &amp;HF7) Or ((isWin10 And 2) * 4)
      i = 24
      Maps = "BCDFGHJKMPQRTVWXY2346789"
      Do
             Current= 0
          j = 14
          Do
             Current = Current* 256
             Current = Key(j + KeyOffset) + Current
             Key(j + KeyOffset) = (Current \ 24)
             Current=Current Mod 24
              j = j -1
          Loop While j &gt;= 0
          i = i -1
          KeyOutput = Mid(Maps,Current+ 1, 1) &amp; KeyOutput
          Last = Current
      Loop While i &gt;= 0
      keypart1 = Mid(KeyOutput, 2, Last)
      insert = "N"
      KeyOutput = Replace(KeyOutput, keypart1, keypart1 &amp; insert, 2, 1, 0)
      If Last = 0 Then KeyOutput = insert &amp; KeyOutput
      ConvertToKey = Mid(KeyOutput, 1, 5) &amp; "-" &amp; Mid(KeyOutput, 6, 5) &amp; "-" &amp; Mid(KeyOutput, 11, 5) &amp; "-" &amp; Mid(KeyOutput, 16, 5) &amp; "-" &amp; Mid(KeyOutput, 21, 5)
  </code></pre>