2016-09-23 10 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

関連する問題