2016-09-23 175 views
3

这工作:如何使用变量名称从对象访问属性?

$psISE.Options.DebugBackgroundColor = '#FFC86400' 

这不:

$attribute = 'DebugBackgroundColor' 
($psISE.Options)[$attribute] = '#FFC86400' 

ERROR: Unable to index into an object of type Microsoft.PowerShell.Host.ISE.ISEOptions

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

有没有办法做到这一点?

回答

2

只需使用双引号后点:

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

在双引号不用了。这项工作很好:'$ psISE.Options。$ attribute'。 – PetSerAl