Need Script to find server activation status

11,796

Solution 1

Here you go, I just made a few tweaks.

For one, your code returns the LicenseStatus as a number...which is OK, but to get some real wow-factor, I consulted this chart from MSDN on what the numbers mean, and used that with a Switch Statement, within a Calulated Property to replace the number with the human-meaningful license status, giving us logic like this:

select Pscomputername,Name,@{Name='LicenseStatus';Exp={

switch ($_.LicenseStatus)
{
0 {'Unlicensed'}
1 {'licensed'}
2 {'OOBGrace'}
3 {'OOTGrace'}
4 {'NonGenuineGrace'}
5 {'Notification'}
6 {'ExtendedGrace'}
Default {'Undetected'}
}
#EndofCalulatedProperty
}}

This gives us full code, like this, and also extracts the name of the product as well. You can run this against multiple systems by just adding their names to the -ComputerName property:

    Get-CimInstance -ClassName SoftwareLicensingProduct -computerName localhost,dc01,windows10 |
     where PartialProductKey | select Pscomputername,Name,@{Name='LicenseStatus';Exp={
        switch ($_.LicenseStatus)
        {
    0 {'Unlicensed'}
    1 {'licensed'}
    2 {'OOBGrace'}
    3 {'OOTGrace'}
    4 {'NonGenuineGrace'}
    5 {'Notification'}
    6 {'ExtendedGrace'}
    Default {'Undetected'}
}
#EndOfCaltulatedProperty
}}

This gives you results like this:

PSComputerName                         Name                                   LicenseStatus                        
--------------                         ----                                   -------------                        
localhost                              Office 15, OfficeProPlusVL_MAK edition licensed                             
localhost                              Windows(R), ServerDatacenter edition   licensed 
dc01                                   Windows(R), ServerStandard edition     licensed
Windows10                              Windows(R), ServerStandard edition     licensed

Solution 2

you may also try

$activation      = (Get-CimInstance -ClassName SoftwareLicensingProduct | where ApplicationId -EQ 55c92734-d682-4d71-983e-d6ec3f16059f | where PartialProductKey).LicenseStatus
Share:
11,796
Admin
Author by

Admin

Updated on July 17, 2022

Comments

  • Admin
    Admin almost 2 years

    We have an environment with different domains and forests with and without trusts.

    I need to manage the license for these with out KMS.

    I want to find out the servers which are running without activated or with Grace period.

    I have been trying with differnt scripts from WMIC and Powershell. But, not able to generate with clear and clean.

    Below are the scripts tried. I need assistance on this.

    From WMIC:

    WMIC /Output:@D:\output.txt /node:@D:\serverslist.txt PATH SoftwareLicensingProduct WHERE "ProductKeyID like '%-%' AND Description like '%Windows%'" get LicenseStatus 
    

    From Powershell:

    PS C:\Windows\system32> Get-CimInstance -ClassName SoftwareLicensingProduct |where PartialProductKey |select PScomputername,LicenseStatus
    

    I need help to generate a table with computer name/IP and license status.

    Thanks in advance.

  • Admin
    Admin about 9 years
    This script is perfect and great, however am not able to run for remote machines and with IP address due to the recrictions set in WINRM. Am Just fighting with it to get it fixed. will update you once i get it fixed. Thanks
  • FoxDeploy
    FoxDeploy about 9 years
    If you want to run this in your whole environment, you'll need to turn on PowerShell remoting. There are group policys you can use for the whole company, or you can do a single PC at a time with 'Enable-PSRemoting -Force' from the Admin PowerShell prompt
  • Admin
    Admin about 9 years
    I have tried many things from enabling psremoting, enabling Https in winrm by creating self signed and assigned cert's, enabling trusted list to all. Not able to get through it. Planning to run on individual domains with domain credentials just as you did and will update you... Thanks
  • Admin
    Admin about 9 years
    I was having similar talk on Scripting Guy too, got the workaround. Please check the link.. Thanks a lot for your help and time. social.technet.microsoft.com/Forums/scriptcenter/en-US/…