PowerShell命令元数据

时间:2016-11-02 13:59:44

标签: windows powershell metadata

我是PowerShell新手。我知道当一个人运行PowerShell命令时,它会发送一个对象流作为输出。

例如:

PS C:\Users\JGodse\scripts> Get-WmiObject -Class win32_Product


IdentifyingNumber : {90150000-008C-0000-0000-0000000FF1CE}
Name              : Office 15 Click-to-Run Extensibility Component
Vendor            : Microsoft Corporation
Version           : 15.0.4867.1003
Caption           : Office 15 Click-to-Run Extensibility Component

IdentifyingNumber : {90150000-008C-0409-0000-0000000FF1CE}
Name              : Office 15 Click-to-Run Localization Component
Vendor            : Microsoft Corporation
Version           : 15.0.4867.1003 
Caption           : Office 15 Click-to-Run Localization Component

IdentifyingNumber : {90150000-008F-0000-1000-0000000FF1CE}
Name              : Office 15 Click-to-Run Licensing Component
Vendor            : Microsoft Corporation
Version           : 15.0.4867.1003
Caption           : Office 15 Click-to-Run Licensing Component


....... (and many more such objects)......

对象具有属性(IdentifyingNumber,Name,Vendor,Version,Caption)。从这里我可以将对象管道输出到这样的东西,以选择名称:

PS C:\Users\JGodse\scripts> Get-WmiObject -Class win32_Product | select name

name
----
Office 15 Click-to-Run Extensibility Component
Office 15 Click-to-Run Localization Component
Office 15 Click-to-Run Licensing Component
Microsoft .NET Framework 4.5.1 Multi-Targeting Pack

有没有办法获取命令返回的对象的属性名列表而不运行命令并直观地解析输出?也许像神话般的Get-Attributes这样的命令:

PS C:\> Get-Attributes Get-WmiObject

attributes
----------
IdentifyingNumber, Name, Vendor, Version, Caption

1 个答案:

答案 0 :(得分:1)

您要查找的cmdlet是get-member,但是它将获取对象上可用的属性,而不是cmdlet可能产生的属性。这是因为根据您提供的参数,您将获得具有不同结果的对象。 (例如,get-wmiobject为不同的类返回不同的对象)。你可以使用下面的东西。

Get-wmiobject win32_operatingsystem | Get-member

这将为您提供表示计算机win32_operatingsystem WMI类的对象可用的所有属性和方法的列表。以下链接包含其他信息和示例。

https://technet.microsoft.com/en-us/library/ee176854.aspx