Powershell ExpandProperty是否在选择对象时不显示其他属性?
我在使用Powershell ExpandProperty是否在选择对象时不显示其他属性?,powershell,Powershell,我在使用select objectcmdlet的-expand参数时遇到问题。我从帮助文件中了解到,我可以获得select object,以输出扩展的属性和其他属性,但这在我的情况下似乎不起作用 以下是帮助文件中的一个示例: PS> Get-Process | select-object Name -expand Modules | fl Name : chrome ModuleName : chrome.exe FileName
select object
cmdlet的-expand
参数时遇到问题。我从帮助文件中了解到,我可以获得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...}
关于我可能做错了什么或者为什么这不起作用,有什么建议吗
谢谢,
拉赫什这是精心设计的。您需要自定义属性。试试这个:
Get-WmiObject Win32_ComputerSystem |
select __CLASS,__SUPERCLASS,__DYNASTY,@{n="__DERIVATION";e={($_ | select -expa __DERIVATION) -join ',' }}| fl *
谢谢你,这很有效(加上逗号的感觉很好,我没想到)。您知道为什么它适用于Get流程示例吗?@RakheshSasidharan,因为您只导出了一个属性。expand参数按设计一次使用一个属性。记住接受这个答案。非常感谢。