在这里,我只是做了一些调整。
其一,你的代码返回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
阅读此[链接](https://technet.microsoft.com/en-us/magazine/2008.06.windowspowershell.aspx)您可以创建psobject然后加上列和值 – powershell 2015-03-31 12:47:16