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



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

我需要管理这些与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:Windowssystem32> Get-CimInstance -ClassName SoftwareLicensingProduct |where PartialProductKey |select PScomputername,LicenseStatus

我需要帮助生成一个包含计算机名称/IP和许可证状态的表。

提前谢谢。

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

首先,您的代码以数字形式返回LicenseStatus。。。这是可以的,但为了获得一些真正的惊喜因素,我查阅了MSDN的这张图表,了解了这些数字的含义,并将其与计算属性中的Switch语句一起使用,将数字替换为人类有意义的许可证状态,给我们提供了这样的逻辑:

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

您也可以尝试

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

最新更新