We need to collect the Windows Product Keys for the computers we have deployed (about 110 of them) in our company.  Microsoft Audit is requiring this information.  Is there a way to get the Product Key information, maybe from the Registry or something?

Answer Summary:
Below is the script to find out product keys.
Cancel
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Community Chosen Answer

4

From http://mspowershell.blogspot.com/2009/02/retrieveing-windows-product-key.html.

#Change for path that you are using.
$file= "c:\temp\keys.txt"
function Get-WindowsKey {
    ## function to retrieve the Windows Product Key from any PC
    ## by Jakob Bindslet (jakob@bindslet.dk)
    param ($targets = ".")
    $hklm = 2147483650
    $regPath = "Software\Microsoft\Windows NT\CurrentVersion"
    $regValue = "DigitalProductId"
    Foreach ($target in $targets) {
        $productKey = $null
        $win32os = $null
        $wmi = [WMIClass]"\\$target\root\default:stdRegProv"
        $data = $wmi.GetBinaryValue($hklm,$regPath,$regValue)
        $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 Caption -value $win32os.Caption
        $obj | Add-Member Noteproperty CSDVersion -value $win32os.CSDVersion
        $obj | Add-Member Noteproperty OSArch -value $win32os.OSArchitecture
        $obj | Add-Member Noteproperty BuildNumber -value $win32os.BuildNumber
        $obj | Add-Member Noteproperty RegisteredTo -value $win32os.RegisteredUser
        $obj | Add-Member Noteproperty ProductID -value $win32os.SerialNumber
        $obj | Add-Member Noteproperty ProductKey -value $productkey
        $obj
    }
}
Get-WindowsKey | format-table ProductKey -HideTableHeaders|Out-File $file

Get-Content $file |select -Skip 1| Set-Content "$file-temp"
move "$file-temp" $file -Force

 

Then create a custom inventory rule to read the file c:\temp\keys.txt.

ShellCommandTextReturn(cmd.exe /c type c:\temp\keys.txt)

You should then be able to run a report based on the custom inventory.

Answered 06/11/2012 by: dugullett
Red Belt

Please log in to comment

Answers

1

I'm using ProduKey to retrieve Windows, Office and related keys.  The potential list is fairly extensive and it's nice because it puts the info right into the Custom Fields section of the machine's inventory.  Mark O'Malley showed me this during my initial training.

Just one thing to be aware of is that Windows Defender (in Win7) may pick this up as a keylogger, but not an issue once it's allowed.

John

_____________________

Here's my script info:

Online KScript

Product Keys

Retrieve Windows & Office product keys.

Uses ProduKey (http://www.nirsoft.net/utils/product_cd_key_viewer.html) to retrieve keys and then saves to file.  Can change output type by changing switch (i.e. /stxt, /stab, /shtml).

Run As User logged in to console.

Dependencies: ProduKey.exe

Verify: Always Fail

Remediation:

- Directory: $(KACE_DEPENDENCY_DIR)

- File: ProduKey.exe

- Wait for startup (checked)

- Parameters: /WindowsKeys 0 /IEKeys 0 /SQLKeys 0 /ExchangeKeys 0 /stext c:\kbox\produkey.txt

_____________________

Here's the Software item setup:

Display Name (Title):  * ProduKey Key Retrieval

Custom Inventory Rule: ShellCommandTextReturn(cmd /c type c:\KBOX\produkey.txt)

Answered 06/15/2012 by: jverbosk
Red Belt

  • I'm a newbie and was wondering about the fields to place your specific information in?
    • If you're new to scripting, this KKE video on scripting basics might help:
      https://support.software.dell.com/kb/186568

      John
      • Thank you I will have to have my manager create an account for me.
Please log in to comment
Answer this question or Comment on this question for clarity