2015-03-31 54 views
0

我们有一个包含和不包含信任的不同域和森林的环境。需要脚本来查找服务器激活状态

我需要管理这些出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和许可状态的表。

在此先感谢。

+0

阅读此[链接](https://technet.microsoft.com/en-us/magazine/2008.06.windowspowershell.aspx)您可以创建psobject然后加上列和值 – powershell 2015-03-31 12:47:16

回答

1

在这里,我只是做了一些调整。

其一,你的代码返回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 
+0

该脚本非常完美,但由于在WINRM中设置了记录,无法运行远程计算机和IP地址。我只是为了争取它而战斗。一旦我修好了会更新你。谢谢 – 2015-04-01 14:40:45

+0

如果你想在整个环境中运行它,你需要打开PowerShell远程处理。您可以为整个公司使用组策略,或者您可以通过Admin PowerShell提示“Enable-PSRemoting -Force”一次完成一台PC。 – FoxDeploy 2015-04-01 15:01:23

+0

我尝试了许多启用psremoting的功能,在winrm中启用Https创建自签名和分配的证书,为所有人启用可信列表。无法通过它。计划使用域凭据在单个域上运行,就像您一样,并且会更新您......感谢 – 2015-04-02 06:09:08

0
Get-CimInstance -ClassName SoftwareLicensingProduct | 
where PartialProductKey | 
select Name, ApplicationId, LicenseStatus 
1

,你也可以尝试

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