Data Centers

Quickly find space-hogging files with PowerShell

A key Windows maintenance chore involves determining what data is consuming resources. Here are a couple of scripts that make it easy to get that critical file information.

Few things are more frustrating than knowing you need to address a low drive space issue but not knowing where to look. NTFS file systems are not the best at calculating total size, much less showing you where the large storage consumption is located. Fortunately, PowerShell — now standard on Windows 7 and Server 2008 — can help the Windows Server (and client) administrator locate areas of the highest disk consumption.

For most low drive space issues, determining what files are over a certain size will be most helpful. You can easily perform this task using a simple PowerShell script created with PowerGUI. Just download the script and save it as a .PS1 file to run in PowerShell on your PC.

This script queries a path either on a local disk or on a remote system's UNC path to see what files exist over a specified size. Figure A shows this script run on a remote server named DB1 for files over 100 MB in the E$ path:

Figure A

The script returns the SQL Server 2008 installation executable that was left on disk, a common occurence that can easily be remediated by deleting the file or storing that type of data centrally. After that bit of housekeeping is done on the path queried, you can rerun the .PS1 file to see if the threshold of large data is still on disk. If you want to rerun the query on a new system or specify a new file size threshold, you can clear out the running values (path, size, unit of measure) by running this PowerShell script (also included in our download):

$global:fdir = ""

$global:fmz = ""

$global:fsize = ""

At that point, the first script can be reiterated with new values for path, size, and unit of measure. You can use the results to resolve problems immediately, notifying desktop users or application owners about large disk consumption.

The day-to-day process of ensuring responsible disk consumption ends up on the Windows admin's shoulders. Do you use PowerShell to manage disk consumption? Share your scripts, tricks, and strategies below.

Additional PowerShell resources


Rick Vanover is a software strategy specialist for Veeam Software, based in Columbus, Ohio. Rick has years of IT experience and focuses on virtualization, Windows-based server administration, and system hardware.

Editor's Picks