gpt4 book ai didi

powershell - ExpandProperty 不显示 Select-Object 的其他属性?

转载 作者:行者123 更新时间:2023-12-04 18:44:12 24 4
gpt4 key购买 nike

我在使用 -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...}

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

谢谢,
拉克什

最佳答案

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

Get-WmiObject Win32_ComputerSystem |
select __CLASS,__SUPERCLASS,__DYNASTY,@{n="__DERIVATION";e={($_ | select -expa __DERIVATION) -join ',' }}| fl *

关于powershell - ExpandProperty 不显示 Select-Object 的其他属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17807932/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com