需要脚本来查找服务器激活状态

Need Script to find server activation status

我们有一个包含不同域和林的环境,有和没有信任。

我需要在没有 KMS 的情况下管理这些许可证。

我想找出 运行 未激活或有宽限期的服务器。

我一直在尝试使用来自 WMIC 和 Powershell 的不同脚本。但是,无法生成清晰干净的。

以下是尝试过的脚本。我需要这方面的帮助。

来自 WMIC:

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

来自 Powershell:

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

我需要帮助生成 table 计算机 name/IP 和许可证状态。

提前致谢。

给你,我只是做了一些调整。

首先,您的代码 returns LicenseStatus 作为数字...这没问题,但为了获得一些真正的惊喜因素,我咨询了 this chart from MSDN on what the numbers mean,并将其与 Switch 一起使用声明,在一个 Calulated 属性 中用人类有意义的许可证状态替换数字,给我们这样的逻辑:

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
}}

这给了我们完整的代码,就像这样,还提取了产品的名称。您可以 运行 通过将它们的名称添加到 -ComputerName 属性:

来针对多个系统
    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
}}

结果如下:

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
Get-CimInstance -ClassName SoftwareLicensingProduct | 
where PartialProductKey | 
select Name, ApplicationId, LicenseStatus

你也可以试试

$activation      = (Get-CimInstance -ClassName SoftwareLicensingProduct | where ApplicationId -EQ 55c92734-d682-4d71-983e-d6ec3f16059f | where PartialProductKey).LicenseStatus