Search code examples
powershellwindows-server-2008-r2wmic

Need Script to find server activation status


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.


Solution

  • 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