Powershell: list files and folder size on a root folder

Luis Diaz
Luis Diaz used Ask the Experts™
on
Hello experts,
I have the following powershell command in order list file size on a root folder.
Get-ChildItem -Path C:\ -Recurse -Force -File -ErrorAction SilentlyContinue |
	Where-Object {$_.Length -gt 50MB} |
	Select-Object Name, FullName, @{n='Length (MB)'; e={[math]::Round(($_.Length / 1MB), 2)}} |
	Export-Csv -NoTypeInformation -Delimiter ';' -Path C:\Temp\BigFiles.csv

Open in new window


Solution reported at:  https://www.experts-exchange.com/questions/29136460

I would like to take it as a reference in order to list list folder size with file size.
How should I proceed it?
Thank you very much for your help.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Bill PrewIT / Software Engineering Consultant
Top Expert 2016

Commented:
Do you just want the top level folders in the root drive, or recursively reporting every subfolder?

The way it's written I think you would explode every folder, and therefore I think you will get a lot of "duplicate" information.  For example if folder "c:\dir1\dir2\dir3\dir4" meets the size criteria for reporting, then the report would show all 4 of those folders as a record, with their sizes.  But the sizes are sort of being counted multiple times.

Maybe you can show a sample output of what you are looking for...


»bp
Luis DiazIT consultant

Author

Commented:
Hello Bill,
Thank you for your help.
You are right, we are going to have a lot of duplicate information.
To avoid this, I was thinking to exclusively list folders size which contains files inside. The rest we can omit it. Let me know what do you think.
Bill PrewIT / Software Engineering Consultant
Top Expert 2016

Commented:
So are you saying if you had these files, all with sizes of 100 bytes:

100 c:\dir1\file1.txt
100 c:\dir1\file2.txt
100 c:\dir1\file3.txt
100 c:\dir1\dir2\file1.txt
100 c:\dir1\dir2\file2.txt
100 c:\dir1\dir2\file3.txt
100 c:\dir1\dir2\file4.txt
100 c:\dir1\dir2\file5.txt

You would want to report the containing folder sizes as:

300 c:\dir1
500 c:\dir1\dir2


»bp
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Luis DiazIT consultant

Author

Commented:
Hello Bill,
Sorry for the delay.
The best will be to generate two files: File-size.txt with the various file-size and Folder-size.txt with the various folder size. Both generation with drill mode.
Thank you very much for your help.
Luis DiazIT consultant

Author

Commented:
Hello Bill,
Could you please help me with this question?
Thank you in advance for your help.
Bill PrewIT / Software Engineering Consultant
Top Expert 2016

Commented:
Still not sure the output you are looking for, can you work up an example of the output you want from a sample folder and file structure?


»bp
Luis DiazIT consultant

Author

Commented:
Hello Bill,

Here is an example of what I am looking for:

C:\Folder: 500kb
C\Folder\file1.txt: 250kb
C\Folder\file2.txt: 250kb

Thank you in advance for your help.
IT consultant
Commented:
I found my solution with the following question:
[link]https://www.experts-exchange.com/questions/29141171[/link].

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial