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

Powershell 需要脚本来查找服务器激活状态,powershell,windows-server-2008-r2,wmic,Powershell,Windows Server 2008 R2,Wmic,我们的环境中有不同的域和森林,有信任和没有信任 我需要管理这些没有KMS的许可证 我想找出哪些服务器在未激活或有宽限期的情况下运行 我一直在尝试使用来自WMIC和Powershell的不同脚本。但是,不能产生清晰和干净 下面是尝试过的脚本。我需要这方面的帮助 来自WMIC: WMIC /Output:@D:\output.txt /node:@D:\serverslist.txt PATH SoftwareLicensingProduct WHERE "ProductKeyID like '%-

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

我需要管理这些没有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作为一个数字返回……这是可以的,但为了获得一些真正的惊喜因素,我参考了,并将其与计算属性中的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
}}
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
这给了我们完整的代码,就像这样,还提取了产品的名称。只需将多个系统的名称添加到-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
}}
这会产生如下结果:

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

阅读本文,您可以创建psobject,然后再加上列和值此脚本非常完美,但由于WINRM中设置的冲突,我无法为远程计算机和IP地址运行。我只是为了修好它而和它搏斗。我一修好就会给你更新。谢谢如果要在整个环境中运行此功能,则需要启用PowerShell远程处理。您可以为整个公司使用组策略,也可以使用Admin PowerShell promptI提供的“Enable PSRemoting-Force”一次性使用一台PC。我尝试了许多方法,包括启用PSRemoting、通过创建自签名和分配的证书在winrm中启用Https、为所有人启用受信任列表。没办法挺过去。正在计划使用域凭据在单个域上运行,与您一样,并将更新您。。。ThanksI也在进行类似的关于脚本编写的演讲,找到了解决办法。请检查链接。。非常感谢你的帮助和时间。