Powershell Best Practice #20: Use full key name for calculated properties

By | October 2, 2015

Best Practice: You should use the full key name for calculated properties (in your scripts).

Explanation:

A calculated property is a hashable (key / value) with two members : name and expression.

Name (or Label) : the name we want to call this property.
Expression : the script block used to calculate the value.

For example, we can change the value of the Expression key in the script block to convert the Length value to MB:

calculated-property-powershell

In interactive mode, you could use the shortened name (N ; E), but not in scripts (I often see scripts using shortened key name on the Internet).

Using the full key name (Name ; Expression) makes the code more clear and clean.


previous-buttonnext-button

Leave a Reply

Your email address will not be published.