How to find large files in PowerShell (using Get-Childitem)
September 8, 2024
This tutorial will tell you how to find large files (more than 2GB, 3GB, 10GB, or any other size). And also how to list large files in PowerShell.
To find files, we will use the Get-Childitem cmdlet. This cmdlet gets elements and child elements in one or more specified locations. The description of the cmdlet is quite convoluted – the thing is that Get-Childitem can work not only with the file system, but also with other storages, such as the Windows registry or environment variables.
But for our purposes this is not important, so we can simply say that the Get-Childitem cmdlet searches for files and directories in the specified folder. As additional parameters, Get-Childitem can accept names (or parts of names) of files to filter the output data. But Get-Childitem can't search by file size, so we'll use another cmdlet Where-Object, which can filter data by specified parameters.
In all commands, the Get-Childitem cmdlet will be used with the -File option, which means to display only files and not show folders.
The following command will search the Z: drive and display files larger than 2 GB:
Get-Childitem -Path Z:\ -File -Recurse -ErrorAction SilentlyContinue | Where-Object {$_.Length -gt 2GB}
Of course, you can edit the path where you want to search for files and the size of the files you want to find to suit your needs.
In general, the command worked as expected and large files were found on the drive. If there is a lot of data, you can sort it. For example, the following command will search the Z: drive for files larger than 2 GB and display them sorted from largest to smallest; in addition, the file sizes will be displayed in a more visual form:
Get-ChildItem -Path Z:\ -File -Recurse -ErrorAction SilentlyContinue | Where-Object {$_.Length -gt 2GB} | Sort-Object length -Descending | Select-Object Name,Directory,@{n='GB';e={"{0:N2}" -F ($_.length/ 1GB)}} | Format-List Name,Directory,GB
Now we can easily find the largest files – very convenient if you are going to process the files manually (for example, delete the largest files or make a backup copy of them).
But what if we just need a list of the largest files? This list can be used to automate subsequent work with large files. If you just want to list large files with their full path, run the following command:
Get-Childitem -Path Z:\ -File -Recurse -ErrorAction SilentlyContinue | Where-Object {$_.Length -gt 2GB} | Format-Table -Property FullName -HideTableHeaders
If you are satisfied with the result, you can save the full path to large files to the list:
Get-Childitem -Path Z:\ -File -Recurse -ErrorAction SilentlyContinue | Where-Object {$_.Length -gt 2GB} | Format-Table -Property FullName -HideTableHeaders > bigfiles.txt
This command is similar to the previous one, for those who always want to stay in the spirit of PowerShell:
Get-Childitem -Path Z:\ -File -Recurse -ErrorAction SilentlyContinue | Where-Object {$_.Length -gt 2GB} | Format-Table -Property FullName -HideTableHeaders | Out-File bigfiles.txt
Get-Content bigfiles.txt
To search for large files and list them in a graphical interface, you can pipe the output to Out-GridView:
Get-ChildItem -Path Z:\ -File -Recurse -ErrorAction SilentlyContinue | Where-Object {$_.Length -gt 2GB} | Sort-Object length -Descending | Select-Object Name,Directory,@{n='GB';e={"{0:N2}" -F ($_.length / 1GB)}} | Out-GridView -Title "Large Files"
If you want to customize the search for large files, you can use the Get-Childitem cmdlet with the -Filter and -Exclude options.
With the -Filter option, you can specify the name or part of the name of the files you are interested in, i.e. only large files with a name matching the pattern specified in the -Filter option will be found. In this case, files larger than 2 Gigabytes that contain the string “DT” in their name will be shown:
Get-Childitem -Path Z:\ -File -Recurse -ErrorAction SilentlyContinue -Filter "*DT*" | Where-Object {$_.Length -gt 2GB}
If desired, you can specify files that should be excluded from the search by using the -Exclude option. For example, in the following example, all files larger than 2 Gigabytes that do not contain the string “.NX” in their name will be found.
Get-Childitem -Path Z:\ -File -Recurse -ErrorAction SilentlyContinue -Exclude "*.NX*" | Where-Object {$_.Length -gt 2GB}
The -Filter and -Exclude options can be added to the Get-Childitem cmdlet in any of the commands shown above.
Note that the -Filter and -Exclude options only apply to the file name, and do not apply to folder or subfolder names.
Related articles:
- PowerShell: how to find only folders with Get-ChildItem (100%)
- What does $_ and $PSItem mean in PowerShell (60.9%)
- How to clear the terminal window in PowerShell. Analog of clear (56.5%)
- Hashtables in PowerShell (strings that start with @) (complete guide) (56.5%)
- How to change the command prompt in Windows Terminal for PowerShell (55.5%)
- How to install the latest PowerShell on Windows 11 (RANDOM - 51%)






