Search notes:

PowerShell: Get an object's property value by a dynamic property name

The value of an object's property whose name is dynamic (for example stored in a variable) can be looked up with $obj.psObject.properties['name'].value:
$obj = new-object psObject -property @{
  num = 42
  txt = 'Hello world'
}

$key = 'num'
write-host "value of $key is $($obj.psObject.properties[$key].value)"
However, such a value can also be looked up by the much shorter syntax $obj.$key:
write-host "value of $key is $($obj.$key)"
If the dynamic property name to be looked up is calculated «in place», parantheses can be used: $obj.( expr ):
$a = 'n'
$b = 'u'
$c = 'm'

write-host "value of $key is $( $obj.($a + $b + $c) )"
This special syntax not only applies to custom objects, but also to «ordinary» objects:
$dir = get-item .
$property = 'LastWriteTime'
$dir.$property

Index