Troubleshooting Fileservers at capacity or with limited space and clearing large, old files

Problem:
Recently I had to find a fast way of clearing space on a fileserver that was literally at bursting point, the 2TB disk had just 100MB free space remaining.  I needed a way to identify the large, old files quickly so that I could then check with the file owners that they could be deleted.

Solution:
This was actually quite an easy fix, I ran the below PowerShell code on the fileserver in question.  This generates a .csv file with a list of every file on the server over 100MB in size.  I could then simply sort by size and age and quickly identify the files that could be cleared that would also generate huge space savings.  I managed to free up over 200GB in about 20 minutes.

Get-ChildItem D:\ -Recurse -ErrorAction "SilentlyContinue" | Where-Object {$_.Length -gt 100MB} | Export-Csv c:\temp\myLargeFilesOnD_Report.csv

 

To use the script simply substitute D:\ with the disk you want to scan and change the Export-Csv path to your own preferred directory.

If you want to add a filter to only show files added in the last day use the $_.CreationTime -gt (Get-Date).AddDays(-1) command as below.

Get-ChildItem D:\ -Recurse -ErrorAction "SilentlyContinue" | Where-Object {($_.Length -gt 100MB) -and ($_.CreationTime -gt (Get-Date).AddDays(-1))} | Export-Csv c:\temp\myLargeFilesOnD_Report.csv

Leave a Reply

Your email address will not be published. Required fields are marked *