/build/static/layout/Breadcrumb_cap_w.png

I would like to record the Windows Product Keys for my computers in my KACE inventory. Is it possible to get that information from an inventory update?

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?


0 Comments   [ + ] Show comments

Answers (2)

Answer Summary:
Below is the script to find out product keys.
Posted by: dugullett 12 years ago
Red Belt
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.


Comments:
  • This runs fine in ISE and when run as ps1 script directly in powershell, yet when ran via KACE script, the only output I get is BBBBB-...
    and a log full of "Cannot index into a null array" Trying to nut out why it would work in one place and not the other.

    Running as Online Shell Script with:
    powershell.exe -nologo -executionpolicy bypass -WindowStyle hidden -noprofile -file getMicroKey.ps1 - tOBdavian 7 years ago
Posted by: jverbosk 12 years ago
Red Belt
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)


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

      John - jverbosk 8 years ago
      • Thank you I will have to have my manager create an account for me. - rbeatty 8 years ago
      • now when I go to remediation it will not allow me to add a new step. - rbeatty 8 years ago
      • Yeah that didn't work for me. I am currently running produkey individually and it's not even pulling all the Microsoft licenses - rbeatty 8 years ago

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ