Powershell & Windows Batch & Vbscript: disk space monitoring & list various files with size and location

Hello experts,

I am having some space disk issues and I would like to monitor this without any installation.

My idea is to launch a command: powershell & windows batch or vbscript in order to:

1-Drill down root folder: C:\
2-List the various files sorted by sizes (highest to lowest) in a csv or txt file with specific locations

This will allows me to check the various files which takes the most and remove them to free up disk space.

If you have questions, please contact me.

Regards,
LVL 1
LD16Asked:
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.

oBdACommented:
Very simple in PowerShell, including a check to only log files over a given size, for example 50MB:
Get-ChildItem -Path C:\ -Recurse -Force -File | Where-Object {$_.Length -gt 50MB} | Select-Object Name, FullName, Length | Export-Csv -NoTypeInformation -Path C:\Temp\BigFiles.csv

Open in new window

LD16Author Commented:
Thank you oBdA, I will test it soon.
Bill PrewIT / Software Engineering ConsultantCommented:
I know you said "monitoring" in the post title, but based on the actual question description it felt more like analysis.  For what it's worth, you should look at TreeSize Free also, it comes in a portable so nothing to install, is small and fast, and does a good job of helping drill down into where the space hogs are.  Even if you use it in conjunction with some scripted monitoring...



»bp
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

LD16Author Commented:
Thank you very  much for this proposal Bill. Do you know if portable versions can also be launched in Server?
When I reported monitoring I meant just to found the files which take the most space.
LD16Author Commented:
oBda three remarks.
1-Is it possible convert the size in Mb or kb?
2-I got some PermissionDenied for files which are located AppData. Possible to omit them? Is there a parameter to report for this?
2019-02-19_20h15_54.png3-For csv export with ";" delimiter what should I report in the command?
Thank you in advance for your help.
oBdACommented:
Try this:
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

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
LD16Author Commented:
Thank you. I will test it soon.
Bill PrewIT / Software Engineering ConsultantCommented:
Yes, it should work on Server.


»bp
LD16Author Commented:
@oBda: the last proposal works fine just a final requirement which can be very helpful:
Sort file length from Ascending to descending.
Do you think this is possible with powershell?
oBdACommented:
Of course that's possible; just be aware that, depending on the amount of files found, significantly more memory might be used, because all the results will have to be stored before they can be sorted.
Without sorting, the elements will just be passed through and directly written to the export file, which requires next to no memory.
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)}} |
	Sort-Object -Property 'Length (MB)' |
	Export-Csv -NoTypeInformation -Delimiter ';' -Path C:\Temp\BigFiles.csv 

Open in new window

LD16Author Commented:
Thank  you for your comment oBdA in that case the best is to avoid sorting and then sorting directly with Excel.
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
Powershell

From novice to tech pro — start learning today.