5

我在使用cmdlet的-expand参数时遇到问题。select-object我从帮助文件中了解到,我可以select-object输出扩展的属性其他属性,但这似乎不适用于我的情况。

按照帮助文件中的示例,以下工作:

PS> Get-Process | select-object Name -expand Modules | fl
Name              : chrome
ModuleName        : chrome.exe
FileName          : C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
BaseAddress       : 10682368
ModuleMemorySize  : 868352
EntryPointAddress : 10980160
FileVersionInfo   : File:             C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
                InternalName:     chrome_exe
                OriginalFilename: chrome.exe
                FileVersion:      28.0.1500.72
...

为我想要的东西尝试同样的方法是行不通的:

PS> Get-WmiObject Win32_ComputerSystem | select -Property __CLASS,__SUPERCLASS,__DYNASTY -expand __DERIVATION | fl
CIM_UnitaryComputerSystem
CIM_ComputerSystem
CIM_System
CIM_LogicalElement
CIM_ManagedSystemElement

如您所见,仅显示了扩展属性的内容;其他所有内容都被跳过。

这是没有扩展属性的输出:

PS> Get-WmiObject Win32_ComputerSystem | select -Property __CLASS,__SUPERCLASS,__DYNASTY,__DERIVATION | fl


__CLASS      : Win32_ComputerSystem
__SUPERCLASS : CIM_UnitaryComputerSystem
__DYNASTY    : CIM_ManagedSystemElement
__DERIVATION : {CIM_UnitaryComputerSystem, CIM_ComputerSystem, CIM_System, CIM_LogicalElement...}

关于我可能做错了什么或为什么这不起作用的任何建议?

谢谢, 拉赫什

4

1 回答 1

8

这是设计使然。您需要自定义属性。尝试这个:

Get-WmiObject Win32_ComputerSystem |
 select __CLASS,__SUPERCLASS,__DYNASTY,@{n="__DERIVATION";e={($_ | select -expa __DERIVATION) -join ',' }}| fl *
于 2013-07-23T11:28:11.867 回答