Test windows activation

I’m currently upgrading my lab environment to Windows Server 2012 R2 which involves upgrading some machines and rebuilding the others.  One task in any build or upgrade situation is to make sure that Windows is activated.

Windows Server 2012 R2 will activate once an Internet connection is established. This can sometimes take a few minutes. Rather than keep checking in the GUI I wrote a little function to do the job for me:

function test-activation {
  $slp = Get-CimInstance -ClassName SoftwareLicensingProduct -Filter "PartialProductKey LIKE '%'"
  if ($slp.LicenseStatus -eq 1) {
    return "$($slp.Name) on $env:COMPUTERNAME is activated"
   }
   else {
    return "$($slp.Name) on $env:COMPUTERNAME is NOT activated"
   }
}

This is based on technique 104 in PowerShell and WMI  - www.manning.com/siddaway2

Get-CimInstance  uses the SoftwareLicensingProduct class and filters on the PartialProductKey property. The filter only picks up those instances where the property has a value.

If the LicensesStatus property equals its activated otherwise it isn’t.

Published Wed, Jan 8 2014 18:45 by RichardSiddaway

Leave a Comment

(required) 
(required) 
(optional)
(required) 
If you can't read this number refresh your screen
Enter the numbers above: