A few years ago I wrote a script to help find the largest files on a drive using PowerShell without the need to install any additional software. This script was extremely useful for quickly narrowing in on files that may be easy to remove in order to help free up disk space, particularly in situations where disk space was critically low. To this day it remains one of my more popular posts/scripts, so I wanted to revisit the script and see if I could add some improvements and make it more flexible with some of the newer PowerShell skills I’ve gained.
You can find the script on my github here:
This script will help locate the largest files on the specified drive, while also displaying
the sizes of the folders in the root directory.
The script will execute in the following order:
– Create a log file, default log name is Get-LargestFiles-output.txt
– Gather the date, hostname, and current privileges
– Gather the basic drive info, capacity and free space (Default drive is C:)
– Gather the root folder sizes
– Find the top x largest files on the drive (Default count is 10)
– Optional scan of a specific directory
C:\PS> PowerShell.exe -ExecutionPolicy Bypass .\Get-LargestFiles.ps1
Specify a different drive and change the amount of files to show:
C:\PS> PowerShell.exe -ExecutionPolicy Bypass .\Get-LargestFiles.ps1 -c “25” -d “d:”
Skip the default root drive scans and only scan a specific directory (you will be prompted for the path):
C:\PS> PowerShell.exe -ExecutionPolicy Bypass .\Get-LargestFiles.ps1 -s