header image

Test windows activation

Posted by: | January 8, 2014 | No Comment |

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.

under: PowerShell and CIM, PowerShell and WMI, PowerShell v4, Windows 2012 R2