在 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”的东西?
当然
write-host ($obj | Select -ExpandProperty "SomeProp")
或者就此而言:
$obj."SomeProp"