Who can help me understand this series of commands?

“”“”“”“”“” Get-ChildItem -Attributes Directory | Format-Table Name,@{Name=‘Size’;Expression={($_ | Get-ChildItem -Recurse | Measure-Object -sum length).sum+0}} “”“”“”“”"

I can’t understand this: “Expression={($_”

It’s clear what it practically does… it calculates the value of the expression and inserts the value into the hash table under the “size” column

What is not clear to me is the function or parameter (I don’t even know what it is), “expression”

I tried to see the get-childitem parameters of format-table but I can’t find expression. I would like to know:

What is this “expression”? property function or something else?

Where can I view this expression function or property? What object is it under? I also tried using get-member but I can’t find “expression”

I hope someone can help me understand, I’m a newbie

Thank you

The expression is called a “Calculated Property”
Calculated Property Documentation
I don’t know if you can really interact with it via things like Get-Member or .GetType(). It’s used with supported cmdlets to manipulate returned properties.
You might also see it abbreviated as @{N=...;E={...}}. That’s how I kept seeing it when I was first learning Powershell and I was very confused what it was about.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.