How it works

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 don't need the semicolon anymore.

Calculated properties come in handy in situation where you don't really want to create a new script, but instead, want some information at the terminal itself, as though running a query. The value of Name is the name of the property, and the values in the column are determined by the expression.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.59.100.42