November 2018
Intermediate to advanced
566 pages
17h 15m
English
A calculated property takes in two things: the name of the property and the expression that would produce the desired result. Technically, this is a hashtable with n (or Name) and e (or Expression) being the two name-value pairs. The Expression in itself is a script block. When broken down into lines, the query looks like this:
Get-ChildItem -File -Recurse | Select-Object Name, LastWriteTime, @{
Name = "Size"
Expression = {
[math]::Round($PSItem.Length/1MB, 3)
}
}
Since we separated the Name and the Expression by a line, we do not need the semicolon anymore.
Calculated properties come in handy in situation where you do not really want to create a new script, but instead want some information at the terminal itself, as though ...
Read now
Unlock full access