How to get filesize in a folder with single command?

Copper Contributor

I am relatively new to Powershell and trying to get to hands on experience of learning it. I am trying to list all files and folders but with their size in MBs. I tried multiple things, but unable to get what I am trying for. Like in Unix I can hit the following: ls -lrh and get the output


I tried and it gives me this:


(gci "C:\Users\test\OneDrive\Word\Client\" | Measure Length -s).sum / 1MB



The final output should be something like this:


Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---l 4/9/2021 12:31 AM 1.7 MB Client_Changes.docx
-a---l 7/21/2021 11:08 AM 6 MB Test_Files.docx
-a---l 7/15/2021 12:58 PM 0.6 MB Test_files2.docx



1 Reply
best response confirmed by Sandeepkv3003 (Copper Contributor)

Something like this

dir | ft -Property mode,lastwritetime, @{Name="Size MB";Expression={$_.Length / 1mb}; format = '0.0'},name