Use Powershell to find all files over a certain size

Powershell can be used to find all files that are over a certain size. Most system administrators are always on the lookout for means and ends to fetch files that are sized over a certain limit on the server and local computers. Powershell can be very handy in providing the resources to scan through the system and find files over a critical threshold limit.

More than anything else, Powershell affords a simple opportunity to perform essential housekeeping and maintenance activities on the file system. It also helps in creating efficient resource retention and deletion policies.

Below, we will look at one of the potential methods that can be used to find files over a certain size on the computer. You can use this command on the local computer or a remote computer and fetch the necessary details anytime.

Before showing you the exact process to fetch details of files over a certain size, we would like to reiterate that Powershell must be already installed on your Windows computer. And, you should be able to launch the Powershell session with administrative privileges.

On a Windows 11 computer, you can bring up a Powershell session by typing the pwsh command in the search box on the Windows toolbar. The screenshot below shows you how can bring up the Powershell session using the pwsh command on the local computer. We need to ensure that the Powershell session starts with administrative privileges.

Pwsh command

Once the Powershell session loads, we can work on providing the commands or directives to find the files over a certain size. For the sake of simplicity, we will discuss two examples. In the first example, we will find files that are over 10 MB in size. For quick results, we will restrict the search space to a specific folder on the C:\. You can replace the search space with a path of your computer.

Find files over 10 MB using Powershell

Before we share the commands, here is what we need to reiterate:

  • We are searching for files over 10 MB in size
  • For faster turnaround, we are restricting the search to a specific path or folder location. You can choose to recursively search through the root drives on your Windows computer. It just takes a bit more time than is needed for the tutorial.
  • The results of files over 10 MB in size are displayed on the screen. You can, if desired, redirect the results to a target text file for documentation reasons.

We will use a couple of commands to find files in a specific folder that are over 10 MB in size.

We will define a variable with file size of 10 MB. We call this variable SIZE, and it can be defined with this command:

$Size=10MB (note, that there are no spaces between 10 and MB)

Now that the variable $Size has been defined, we will use the Get-ChildItem cmdlet to find all files within a folder that are over 10 MB in size. For this, we will use the logical operator as well. Here is the command that can be used to find all files over 10 MB in size within a specific folder on the Windows computer.

Get-ChildItem c:\users\hp\documents\ -Recurse | Where-Object {$_.Length -gt $size}

This cmdlet will look within the folder location recursively to find files that are over 10 MB in size. The output of these two commands looks like the screenshot below.

You can see that the Powershell cmdlet was able to find 6 files that are over 10 MB in size within the specific folder location.

Find files over 1 GB on a Windows computer using Powershell

On a similar note, if you were to find all files on a Windows computer that are over 1 GB in size, you can specify the variable and use the Get-ChildItem cmdlet to fetch the files from the computer.

We will use the following two commands:

  • $size=1GB
  • Get-ChildItem c:\test1 -Recurse | Where-Object {$_.Length -gt $size}

Through these two commands, we have created a variable and assigned a value of 1 GB to it. In the second command, we are looking for files within C:\test1 folder path location to fetch details of files that are over 1 GB in size. the output of this command is displayed hereunder as screen capture.

Find files over 1 GB in size using Powershell in Windows

You can see that we were able to find a file test2.zip that is over 1 GB in size within the path location provided in the command.

Rajesh Dhawan

Rajesh Dhawan is a technology professional who loves to blog about smart wearables, Cloud computing and Microsoft technologies. He loves to break complex problems into manageable chunks of meaningful information.