Powershell 如何使用变量名从对象访问属性?

Powershell 如何使用变量名从对象访问属性?,powershell,object,powershell-5.0,Powershell,Object,Powershell 5.0,这项工作: $psISE.Options.DebugBackgroundColor = '#FFC86400' 这并不是: $attribute = 'DebugBackgroundColor' ($psISE.Options)[$attribute] = '#FFC86400' 错误:无法索引到Microsoft.PowerShell.Host.ISE.ISEOptions类型的对象 我想使用$attribute变量在foreach循环中设置选项属性 有没有办法做到这一点?只需在点后使用

这项工作:

$psISE.Options.DebugBackgroundColor = '#FFC86400'
这并不是:

$attribute = 'DebugBackgroundColor' 
($psISE.Options)[$attribute] = '#FFC86400'
错误:无法索引到Microsoft.PowerShell.Host.ISE.ISEOptions类型的对象

我想使用
$attribute
变量在
foreach
循环中设置选项属性


有没有办法做到这一点?

只需在点后使用双引号:

$attribute = 'DebugBackgroundColor'
$psISE.Options."$attribute"

不需要双引号。这项工作很好:
$psISE.Options.$attribute