我们的环境具有不同的域和森林,有或没有信任。
我需要在没有 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/