How to Get Windows Activation Status Using PowerShell?

Recently, one of my clients in New York asked me about getting the Windows activation status of a small office network. You can get it using PowerShell. In this tutorial, I will explain how to get Windows activation status using PowerShell.

Note: Make sure you have the administrator access to the systems you want to check.

Let’s get started.

Get Windows Activation Status Using PowerShell Using WMI

Windows Management Instrumentation (WMI) provides a standardized way to interact with system components. To check the activation status of a Windows machine, we will query the SoftwareLicensingProduct class.

Here is a simple PowerShell script to get the activation status:

$wmiObject = Get-WmiObject -Query "SELECT * FROM SoftwareLicensingProduct WHERE PartialProductKey <> null AND LicenseFamily <> null"
foreach ($item in $wmiObject) {
    if ($item.ApplicationID -eq "55c92734-d682-4d71-983e-d6ec3f16059f") {
        Write-Output "Product Name: $($item.Name)"
        Write-Output "License Status: $($item.LicenseStatus)"
        Write-Output "Partial Product Key: $($item.PartialProductKey)"
    }
}

Output

It would help if you now understood the output.

The script above retrieves the activation status of Windows installations. The LicenseStatus property can have the following values:

  • 0: Unlicensed
  • 1: Licensed
  • 2: Initial Grace Period
  • 3: Additional Grace Period
  • 4: Non-Genuine Grace Period
  • 5: Notification
  • 6: Extended Grace Period

For example, if you run this script on a workstation in your Los Angeles office, you might see an output like this:

Product Name: Windows(R), Professional edition
License Status: 1
Partial Product Key: ABCDE

This indicates that the Professional Edition of Windows is licensed and activated.

I executed the above PowerShell script, and you can see the exact output in the screenshot below:

Get Windows Activation Status Using PowerShell

Check out How to List Printers Using PowerShell?

Get Windows Activation Status for Multiple Machines

If you manage multiple machines, manually checking each one can be time-consuming. PowerShell can help automate this process. Below is a script that checks the activation status of multiple remote computers:

$computers = @("NYC-PC01", "LA-PC02", "CHI-PC03") # Add your computer names here

foreach ($computer in $computers) {
    try {
        $wmiObject = Get-WmiObject -Query "SELECT * FROM SoftwareLicensingProduct WHERE PartialProductKey <> null AND LicenseFamily <> null" -ComputerName $computer
        foreach ($item in $wmiObject) {
            if ($item.ApplicationID -eq "55c92734-d682-4d71-983e-d6ec3f16059f") {
                Write-Output "Computer: $computer"
                Write-Output "Product Name: $($item.Name)"
                Write-Output "License Status: $($item.LicenseStatus)"
                Write-Output "Partial Product Key: $($item.PartialProductKey)"
                Write-Output "------------------------------"
            }
        }
    } catch {
        Write-Output "Failed to connect to $computer"
    }
}

The script includes a try-catch block to handle any errors that might occur when connecting to remote computers. This ensures that the script continues running even if it encounters an essential issue with one of the machines.

Check out Get a List of Installed Programs Using PowerShell

Download Windows Activation Status Report using CSV

For larger environments, you might want to export the results to a CSV file for easier analysis. Here’s how to modify the script to save the output to a CSV file:

$computers = @("NYC-PC01", "LA-PC02", "CHI-PC03") # Add your computer names here
$results = @()

foreach ($computer in $computers) {
    try {
        $wmiObject = Get-WmiObject -Query "SELECT * FROM SoftwareLicensingProduct WHERE PartialProductKey <> null AND LicenseFamily <> null" -ComputerName $computer
        foreach ($item in $wmiObject) {
            if ($item.ApplicationID -eq "55c92734-d682-4d71-983e-d6ec3f16059f") {
                $results += [PSCustomObject]@{
                    ComputerName     = $computer
                    ProductName      = $item.Name
                    LicenseStatus    = $item.LicenseStatus
                    PartialProductKey = $item.PartialProductKey
                }
            }
        }
    } catch {
        $results += [PSCustomObject]@{
            ComputerName     = $computer
            ProductName      = "N/A"
            LicenseStatus    = "Failed to connect"
            PartialProductKey = "N/A"
        }
    }
}

$results | Export-Csv -Path "C:\ActivationStatusReport.csv" -NoTypeInformation

This script collects the activation status from multiple computers and saves the results to a CSV file named ActivationStatusReport.csv.

Conclusion

In this tutorial, I explained how to get Windows activation status using PowerShell; I ran it, and you saw the exact status. Using the complete PowerShell script, I have also shown how to find Windows activation status for multiple machines. Do let me know in the comment below if this works for you.

You may also like the following tutorials:

100 PowerShell cmdlets download free

100 POWERSHELL CMDLETS E-BOOK

FREE Download an eBook that contains 100 PowerShell cmdlets with complete script and examples.