在這裏,我只是做了一些調整。
其一,你的代碼返回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