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).


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:


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.


Leave a Reply

Your email address will not be published.