Infrastructure

Find the Largest Files on your Computer

update: 10/11/2017
Made -CSV a switch rather than string
update: 6/6/2017
If you want to run this script on Windows 7, you’ll need to install Windows Management Framework 3.0 first. 

I have a decent sized SSD and found it running low on free space. I thought, “what is taking so much space?”  After an unsuccessful internet search, I decided to write my own script to help me find those large files.

I decided to add parameters to make a given search more customizable. For example, the defaults are 10 largest files on your local machine and local hard-drives. However, you can specify more files (e.g.: 100) or you can search USB drives or remote computers, and save output to CSV files.

Here is the full list of parameters and a few examples. The parameters are positional in the following order. If you choose not to specify any parameters, there are defaults of top 10, local machine,  and local disks. 

Parameters
Top = default is 10, this is number of largest files to find in search
ComputerName = default is localhost, but you can specify to remote computer
DriveType = default is 3, but you can override with numeric value below.  These are based on Get-WmiObject CmdLet.

  • Unknown (0)
  • No Root Directory (1)
  • Removable Disk (2)
  • Local Disk (3)
  • Network Drive (4)
  • Compact Disc (5)
  • RAM Disk (6)

CSV = this is a switch. If used, results will output to csv file. If not used, results will output to screen. 

Examples
Search defaults (10 files, local drives, local computer, display output)
C:\Find-LargeFiles.ps1

Search USB drive for 10 largest files, display output
C:\Find-LargeFiles.ps1 -DriveType 2

Search for 20 largest files on remote computer
C:\Find-LargeFiles.ps1 -Top 20 -ComputerName remote-machine-name

Search for 100 largest files and output to csv
C:\Find-LargeFiles.ps1 -Top 100 -CSV

Search top 20 and output to CSV (see screenshot)

 

 

Please download script here:  Find-LargeFiles_v1.2

(Note: Windows PowerShell needs to be configured to run scripts. To do this, run the following command in an elevated Windows PowerShell session (open PowerShell by selecting Run as administrator). Type the following to allow the script to run in your current PowerShell session only.)

For more information on execution policy, see Set-ExecutionPolicy.

Leave a Reply