P1INF: Windows License Activation Status [PowerShell]


Issue

All Windows servers within all the PremierOne environments should have valid activate licenses.

When logged into a server one of the clear indications licensing is not valid is a warning about activating Windows in the lower right hand corner of the screen.

Any servers identified as not having valid licenses need to be corrected.

The purpose of this article is to provide a PowerShell script and guidance on how to query all the servers with PremierOne for their current Windows License Status.

The PowerShell script will generate a txt file with license information for each server within PremierOne.
The values of the output are included in the PowerShell script and provided below:

0 – Unlicensed
1 – Licensed
2 – OOBGrace
3 – OOTGrace – the computer configuration has been changed, and it cannot be activated automatically, or more than 180 days passed
4 – NonGenuineGrace
5 – Notification – Windows trial period is over
6 – ExtendedGrace (you can extend the Windows evaluation period several times using the slmgr /rearm command or convert the evaluation to a full version)

 

Example Output showing LicenseStatus of Notification which indicates Windows trial period is over.

Environment

In order to use the attached PowerShell script the Get-ADComputer cmdlet the ActiveDirectory module must be installed.  Normally, this is already included by default, but I have seen where it was not already present. For most systems this has already been added to the PINFHC01 server and where this server is not present it has been installed either on PCADAPP01-T or PCADRDW01.  Motorola support currently uses the ActiveDirectory module and cmdlets to retrieve Active Directory Users for password expirations daily.

Perform the following:

  • Execute get-module -listavailable from a PowerShell command prompt
  • Look for ActiveDirectory as illustrated below.

If it is not present, you will need to import it using these commands from a PowerShell command prompt.

  • Import-Module ServerManager
  • Add-WindowsFeature RSAT-AD-PowerShell

You will see it going through an installation process...

When complete you should see a successful message.

For more information regarding the ActiveDirectory module and the Get-ADComputer PowerShell cmdlet, please refer to the Microsoft articles below:

Resolution

Copy the attached PowerShell script to a server where the ActiveDirectory module is currently installed (again likely PINFHC01 already by default)

AD_Computers_Check_Windows_Activation_Status.ps1

  • Launch PowerShell as administrator
  • Open the PowerShell script to edit it
  • In the top section update the following as necessary:
    • $customer (use the customer acronym)
    • $currTime (only change if you want a different format for the date/time in the txt file name)
    • $outPutFile (change if you want to output the txt file to a different location)
      • Note: By default the location is the root of D: on the server the script is executed. If you change the output location make sure the output location is valid. There is no logic to validate the output location and it will not create folders for you. The script will only create the file in the location you specify.

 

The PowerShell script will check each server in the Premier-One.local domain for connectivity and current Window's license status.
You will see the script going through the IPs as illustrated below:

It will take a several minutes to complete depending on the number of servers are in the domain.
You may see some errors indicating some servers were not reachable.