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.

This entry was posted in CIM, PowerShell and WMI, PowerShell v4, Windows Server 2012 R2. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s