小编典典

如何通过属性名称获取对象的属性值?

all

在 PowerShell 中,如何通过指定对象的名称(字符串)来获取对象的属性值?我想要以下内容:

$obj = get-something

# View the object's members:
$obj | gm

# I could retrieve a property by doing so:
write-host $obj.SomeProp

# But for many purposes, I would really want to:
write-host $obj | Get-PropertyByName "SomeProp"

PowerShell中是否有类似于“Get-PropertyByName”的东西?


阅读 169

收藏
2022-08-24

共1个答案

小编典典

当然

write-host ($obj | Select -ExpandProperty "SomeProp")

或者就此而言:

$obj."SomeProp"
2022-08-24