Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access a property from an object using a variable name?

Tags:

This works:

$psISE.Options.DebugBackgroundColor = '#FFC86400'

This doesn't:

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

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

I want to set option attributes in a foreach loop using the $attribute variable.

Is there a way to do this?

like image 872
jott19 Avatar asked Sep 23 '16 18:09

jott19


1 Answers

Just use double quotes after the dot:

$attribute = 'DebugBackgroundColor'
$psISE.Options."$attribute"
like image 64
Martin Brandl Avatar answered Sep 24 '22 16:09

Martin Brandl