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

标签 powershell windows-server-2008-r2 wmic

我们的环境具有不同的域和森林,有或没有信任。

我需要在没有 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

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

提前致谢。

最佳答案

给你,我刚刚做了一些调整。

首先,您的代码将 LicenseStatus 作为数字返回...这没关系,但为了获得一些真正的令人惊叹的因素,我咨询了 this chart from MSDN on what the numbers mean ,并在计算属性中将其与 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

关于powershell - 需要脚本来查找服务器激活状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29368414/

相关文章:

powershell - 如何在Powershell中转义 "and '的混合物?

mysql - 没有可用的缓冲区空间(达到最大连接数?

command-line - 如何在 wmic 输出中设置列顺序?

php - Windows Server 在下一个页面加载后无法保持我的 session

xslt - Wmic/格式开关无效的 XSL?

windows - 如何从 wmic 输出中删除空行?

arrays - PowerShell 杀死多个进程

git - 用于锁定 Azure git 中的分支的 API

PowerShell 错误以首选语言输出

Mongodb 修补程序 KB2731284