Powershell: list files and folder size on a root folder

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.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewIT / Software Engineering ConsultantCommented:
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...

LD16Author 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 ConsultantCommented:
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

Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

LD16Author 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.
LD16Author Commented:
Hello Bill,
Could you please help me with this question?
Thank you in advance for your help.
Bill PrewIT / Software Engineering ConsultantCommented:
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?

LD16Author 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.
LD16Author Commented:
I found my solution with the following question:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.