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:
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.
1 2 3 4 5 |
# Good (full key name) Get-ChildItem | Select-Object -Property FullName, @{Name = 'Size (MB)'; Expression = { '{0:N2}' -f ($_.Length / 1MB)}} # Bad (shortened key name) Get-ChildItem | Select-Object -Property FullName, @{N= 'Size (MB)'; E= { '{0:N2}' -f ($_.Length / 1MB)}} |