In order to get the value of a object's property whose name is stored in a variable, I use the following construct:
# Create object $obj = new-object psObject -property @{ num = 42; txt = 'Hello world' } # Name of property whose value I want: $key = 'txt' # Get value $val = $obj.psObject.properties[$key].value $val
I am wondering if $obj.psObject.properties[$key].value can somehow be abbreviated.
$obj.psObject.properties[$key].value
Getting the value directly from a property where the property name (txt) is stored in a variable ($key) can be done like this;
txt
$key
$obj.$key
1.4m articles
1.4m replys
5 comments
57.0k users