Use PowerShell to Detect Activation Status

Summary: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell and WMI to display Windows activation status.

Hey, Scripting Guy! Question Hey, Scripting Guy! The previous network administrator at my company was not attentive to his work. I am not sure what he actually did for a living, but it certainly was not network administration. I think he was a professional Internet surfer. I suspect that many of our desktop operating systems are not activated properly. I want to produce a list of desktop systems, get the names and versions of the operating systems, and find out if the system is activated properly. Can I do this with Windows PowerShell?


Hey, Scripting Guy! Answer Hello DB,

Microsoft Scripting Guy, Ed Wilson, is here. This morning I am still sore from my session with my new personal trainer. In fact, I am pretty sure that I am sore in muscles that I did not know that I had. I guess that means it is working…we will see. I am sipping a cup of Oolong tea this morning. Normally, I would have a black tea in the morning, but this morning, for some reason, I thought that Oolong would do the trick.

I brought back some very nice Oolong tea from Leipzi, Germany earlier this year, and I have been saving it for special occasions. I feel like this morning is a special occasion. With Oolong, especially a very nice Oolong, I do not add anything to the tea. No cinnamon stick, no lemon, no milk, and especially no sugar. Only tea. The Oolong has a very complex flavor, and I can close my eyes and taste the natural sweetness of the tea. There is no need to mess around with something that is already perfect.

Windows Management Instrumentation

There are numerous ways to access Windows Management Instrumentation (WMI) information by using Windows PowerShell. The best way is to use the CIM cmdlets. The CIM cmdlets shipped in Windows PowerShell 3.0 (with Windows 8 and Windows Server 2012), so they have been around for a while. The WMI team wrote a great article about CIM cmdlets on the Windows PowerShell Blog that you may want to read: Introduction to CIM Cmdlets.

To find information about current versions of Windows, I can use the SoftwareLicensingProduct WMI class. (For versions earlier than Windows 7, other WMI classes are required). The SoftwareLicensingProduct class is documented on MSDN, and it contains numerous methods that permit network administrators to completely manage Windows licensing. Two of the more useful methods (for me anyway) are the Active and the UninstallProductKey methods, both of which are pretty much self-explanatory as to what they do.

One reason for using the Get-CimInstance cmdlet is that I can create a CIM session pretty much automatically. This is because it relies on WINRM for remoting. It uses the same remoting technology as other Windows PowerShell remoting. This means that it is automatically activated and it simply works in Windows Server 2012 R2 and Windows Server 2012.

For desktop operating systems, WinRM needs to be enabled, but that is easy enough to do via Group Policy (in larger environments) or via a logon script (for smaller environments). If you have been using Windows PowerShell for a while to manage your network, chances are good that you already have WinRM enabled.

I can easily query Active Directory Domain Services (AD DS) by using the Get-Computer cmdlet to retrieve a list of the computers I want to check. I can then feed that list to the New-CimSession cmdlet to create CIM sessions, and then I can use Get-CimInstance to retrieve my information.

That is how I might modify things to run against all of the computers on my network. For output, I would probably pipe the results to Export-CSV to create a nice file that I can open in Microsoft Excel for my documentation.

Getting licensing status

I am going to use the Get-CimInstance cmdlet to query the SoftwareLicensingProduct WMI class, and to find the ApplicationID for my version of Windows. This is sort of a magic number, and it takes a bit of searching on the Internet to find the information (it is not in the MSDN article for the WMI class).

I use the Get-CimInstance Windows PowerShell cmdlet, specify the WMI class, and pick up the ComputerName value from the environmental variable. I specify the ApplicationID property value for my filter, and I look for a LicenseStatus of 1 (this means it is activated, and this enumeration value does come from the MSDN article).

Then I select the name and description of the product, and I create a custom property that includes the name of the computer. For this example, I throw it to Format-List so I can see my results. Here is the script:

Get-CimInstance SoftwareLicensingProduct -ComputerName $env:computername  `

            -Filter "ApplicationID = '55c92734-d682-4d71-983e-d6ec3f16059f'" |

             where licensestatus -eq 1  |

             Select name, description, @{Label='computer';

             Expression = {$_.PscomputerName}} |

             Format-List  name, description, computer 

The use of the script and the associated output are shown in the following image:

Image of command output

DB, that is all there is to using Windows PowerShell to detect product activation status. WMI Week will continue tomorrow when I will talk about more cool stuff.

I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

Ed Wilson, Microsoft Scripting Guy 

Comments (7)

  1. nick says:

    Oops, I think you’ve got a typo. When you want to query ADDS for computer accounts, I believe you would use Get-ADComputer, instead of just Get-Computer…

  2. An Average German Powershell Scripter says:

    I’m almost sure it’s just a typo but the name of the German city is Leipzig (with a ‘g’ at the end) 😉

    … and btw: thanks for sharing all your cool knowledge with us, it’s great and I love it.

    If you ever come to Berlin, Germany drop me a line I’ll invite you to a good German beer (or a tea) 😀

  3. RoyB says:

    And if you are stuck with PS2?

  4. JPD says:

    Hi Scripting Guy!

    On my KMS activated Server 2012 (slmgr /dlv says "License Status: Licensed" and slmgr /ato "Product Activated Successfully") the Value of "LicenseStatus" equals 0. Is that because of KMS activation or am I missing something else?

  5. JPD says:

    Ignore my question, I just found out about the different channels… I didn’t look in the VOLUME_KMSCLIENT channel…

  6. Ross Presser says:

    When I try this on my new Server 2012 instance (which I happen to know is not activated), I get this error:

    Get-CimInstance : The client cannot connect to the destination specified in the request. Verify that the service on the destination is running and is accepting requests. Consult the logs and documentation for the WS-Management service running on the destination,
    most commonly IIS or WinRM. If the destination is the WinRM service, run the following command on the destination to analyze and configure the WinRM service: "winrm quickconfig".
    At line:1 char:1
    + Get-CimInstance SoftwareLicensingProduct -ComputerName $env:computername `
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ConnectionError: (:) [Get-CimInstance], CimException
    + FullyQualifiedErrorId : HRESULT 0x80338012,Microsoft.Management.Infrastructure.CimCmdlets.GetCimInstanceCommand
    + PSComputerName : PRESSERO2

    When I run Winrm quickconfig I am told:

    WinRM service is already running on this machine.
    WinRM is already set up for remote management on this computer.

Skip to main content