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

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/Windows/...', 1758186887, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/Windows/PowerShell/language/object/get-property-value-by-dynamic-property-name(56): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78