Managing Windows License Key (Part 4)

by Feb 28, 2019

Slmgr.vbs is an ancient VBScript used to automate Windows license management. In the previous tip we started bypassing slmgr.vbs by reading the WMI directly. Aside from the SoftwareLicensingService WMI class which we already covered, there is another one called SoftwareLicensingProduct which has many instances and takes some time to retrieve:

 
Get-WmiObject -Class SoftwareLicensingProduct | Out-GridView 
 

The Description column reveals that this class represents the many different license types available for Windows, only some of which are actually licensed. To get useful information, you’d have to filter the information for only the licenses that are in use.

Use a server-side filter with the -Filter parameter in order to considerably speed the query up. Make sure WMI only returns instances that actually have a non-null ProductKeyId:


 
Get-WmiObject -Class SoftwareLicensingProduct -Filter 'ProductKeyId != NULL' | Select-Object -Property Name, Description, LicenseStatus, EvaluationEndDate, PartialProductKey, ProductKeyChannel, RemainingAppRearmCount, trustedTime, UseLicenseUrl, ValidationUrl | Out-GridView 
 

The result goes to a grid view window and looks similar to this:


 
Name                   : Office 16, Office16ProPlusR_Grace edition
Description            : Office 16, RETAIL(Grace) channel
LicenseStatus          : 5
EvaluationEndDate      : 16010101000000.000000-000
PartialProductKey      : XXXXX
ProductKeyChannel      : Retail
RemainingAppRearmCount : 1
trustedTime            : 20190203111404.180000-000
UseLicenseUrl          : https://activation.sls.microsoft.com/SLActivateProduct/SLActivateProduct.asmx?c
                         onfigextension=o14
ValidationUrl          : https://go.microsoft.com/fwlink/?LinkID=187557

Name                   : Office 16, Office16ProPlusMSDNR_Retail edition
Description            : Office 16, RETAIL channel
LicenseStatus          : 1
EvaluationEndDate      : 16010101000000.000000-000
PartialProductKey      : XXXXX
ProductKeyChannel      : Retail
RemainingAppRearmCount : 1
trustedTime            : 20190203111404.622000-000
UseLicenseUrl          : https://activation.sls.microsoft.com/SLActivateProduct/SLActivateProduct.asmx?c
                         onfigextension=o14
ValidationUrl          : https://go.microsoft.com/fwlink/?LinkID=187557

Name                   : Windows(R), Professional edition
Description            : Windows(R) Operating System, OEM_DM channel
LicenseStatus          : 1
EvaluationEndDate      : 16010101000000.000000-000
PartialProductKey      : XXXXX
ProductKeyChannel      : OEM:DM
RemainingAppRearmCount : 1001
trustedTime            : 20190203111405.221000-000
UseLicenseUrl          : https://activation-v2.sls.microsoft.com/SLActivateProduct/SLActivateProduct.asm
                         x?configextension=DM
ValidationUrl          : https://validation-v2.sls.microsoft.com/SLWGA/slwga.asmx
 

As you can see, dates are returned in WMI format. Use Get-CimInstance instead of Get-WmiObject to return “real” DateTobjects instead:ime


 
PS> Get-CimInstance -Class SoftwareLicensingProduct -Filter 'ProductKeyId != NULL' | Select-Object -Property Name, Description, LicenseStatus, EvaluationEndDate, PartialProductKey, ProductKeyChannel, RemainingAppRearmCount, trustedTime, UseLicenseUrl, ValidationUrl  
 

Your learning points:


    • Individual license information for Microsoft products (including Office) are represented by the SoftwareLicensingProduct WMI class
    • Use Get-CimInstance instead of Get-WmiObject if you want PowerShell to return readable DateTime objects instead of the cryptic WMI datetime format


psconf.eu – PowerShell Conference EU 2019 – June 4-7, Hannover Germany – visit www.psconf.eu There aren’t too many trainings around for experienced PowerShell scripters where you really still learn something new. But there’s one place you don’t want to miss: PowerShell Conference EU – with 40 renown international speakers including PowerShell team members and MVPs, plus 350 professional and creative PowerShell scripters. Registration is open at www.psconf.eu, and the full 3-track 4-days agenda becomes available soon. Once a year it’s just a smart move to come together, update know-how, learn about security and mitigations, and bring home fresh ideas and authoritative guidance. We’d sure love to see and hear from you!

Twitter This Tip! ReTweet this Tip!