Chapter 7 | Selecting Your Own Custom Property
- File size can be accessed through
$_.Length
property. However it shows in Bytes.
- Lets Customise it and get in MB
Get-ChildItem C:\Windows\System32\ | Sort-Object Length -Descending |
Select-Object @{name="Size(MB)";expression={$_.Length / 1MB -as [int]}} -First 10 |
Format-Table -AutoSize
- Notice, the
Name
and Expression
can be shortened as n
and e
i.e. @{n="Size(MB)";e={$_.Length / 1MB -as [int]}}

Get-ChildItem c:\windows\system32 | select @{n="Last Modified Date";e={$_.LastAccessTime.tostring("yyyy-dd-MM")}}, FullName, mode -first 10
