我是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、Version)。由此,我可以通过管道将对象输送到这样的地方,以选择名称:
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属性的命令:
PS C:\> Get-Attributes Get-WmiObject
attributes
----------
IdentifyingNumber, Name, Vendor, Version, Caption发布于 2016-11-02 14:25:43
您要寻找的cmdlet是get成员,但是它将为您获取对象上可用的属性,而不是那些可能由cmdlet产生的属性。这是因为根据您提供的参数,您将获得具有不同结果的对象。(例如,get-wmiobject为不同的类返回不同的对象)。你会用到下面这样的东西。
Get-wmiobject win32_operatingsystem | Get-member
这将获得表示计算机win32_operatingsystem WMI类的对象可用的所有属性和方法的列表。下面的链接有更多的信息和例子。
https://stackoverflow.com/questions/40381826
复制相似问题