Search notes:

PowerShell: Calculated Properties

Defining a calculated property

A calculated property is defined with a hash table.
Depending on the cmdLet where the calculated property is used, one or more of the following key-names are required or optional:
name or label Specifies the calculated property's name.
expression A script block to evaluate the calculated property's dynamic value.
alignment Possible values are 'left', 'right' or 'center', used in ConvertTo-HTML and Format-Table
formatstring
width Maximum width of a column, used in ConvertTo-HTML and Format-Table
depth
ascending and/or descending A boolean value that specifies the ordering.
Key names can be abbreviated, for example with e or expr for expression.

Example

0 .. 50 | foreach-object {
   [int] $x = 31 + [Math]::Sin($_/25*[Math]::Pi) * 30
   [psCustomObject] @{ x = $x}
} |
format-table @{
  expr = { (' ' *$_.x)+'*' }
  name = 'sine'
}

See also

Using calculated properties in select-object.

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/...', 1746782483, '18.119.112.17', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/Windows/PowerShell/language/object/member/property/calculated/index(67): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78