saasrankedSoftware, ranked on the facts

Find large files in PowerShell with Get-ChildItem and Sort-Object

Applies to Windows PowerShell 5.1, PowerShell 7 · 5 min · Beginner
Checked against Microsoft's documentation on 26 Sept 2026

In short

  • Get-ChildItem -Recurse gets the items in a folder and in all its child folders, and -File limits the results to files1.
  • Sort-Object sorts in ascending order by default, so add -Descending to put the largest Length first2.
  • Select-Object -First 10 keeps the first 10 objects of the sorted list3.
  • In PowerShell 6.0 and later, Sort-Object -Top 10 returns the first 10 sorted objects without Select-Object2.
  • -Force adds hidden and system files, but it doesn't override security restrictions1.

To find the largest files on a drive, list every file with Get-ChildItem -Recurse -File1. Pipe the list to Sort-Object -Property Length -Descending, so the biggest files come first2. Then keep the top of the list with Select-Object -First 103. Length is the file size that Get-ChildItem shows by default1. Add -Force to include hidden and system files1.

Syntax

The command chains three cmdlets with the pipeline. Get-ChildItem lists the files, Sort-Object puts them in size order, and Select-Object keeps the top of the list1,2,3.

PowerShell
Get-ChildItem -LiteralPath <folder> -Recurse -File |
    Sort-Object -Property Length -Descending |
    Select-Object -First <number>
  • -LiteralPath is the folder to search. PowerShell uses it exactly as typed and reads no characters as wildcards1.
  • -Recurse gets the items in that folder and in all its child folders1.
  • -File returns files only. It works in the FileSystem provider1.
  • -Property Length sorts on Length, the file size that Get-ChildItem lists by default1,2.
  • -Descending sorts from largest to smallest. The default is ascending order2.
  • -First keeps that number of objects from the start of the list3.

Why -LiteralPath and not -Path? With -Recurse, Get-ChildItem treats the last part of a -Path value as something to search for. Microsoft advises you to avoid -Path with -Recurse and to name the target folder with -LiteralPath instead1.

Examples

Find the 10 largest files on drive C

This lists every file on C: and in its subfolders, sorts the files by size and keeps the 10 largest1,2,3.

PowerShell
Get-ChildItem -LiteralPath C:\ -Recurse -File |
    Sort-Object -Property Length -Descending |
    Select-Object -First 10

It returns 10 file objects. They show with the usual Get-ChildItem columns: Mode, LastWriteTime, Length and Name, under Directory: headings that name each folder1.

Show the full path and the size in megabytes

A calculated property turns Length into a size you can read. The Select-Object docs build one with a Label and an Expression, and divide Length by 1KB3. This version divides by 1MB, which PowerShell reads as 1,024 squared4.

PowerShell
$size = @{Label="Size(MB)";Expression={$_.Length/1MB}}
Get-ChildItem -LiteralPath C:\ -Recurse -File |
    Sort-Object -Property Length -Descending |
    Select-Object -First 10 -Property FullName, $size

It returns a table with two columns. FullName is the full path of each file2, and Size(MB) is the calculated size3.

Include hidden and system files

By default, Get-ChildItem doesn't show hidden items. Add -Force to get hidden and system files too1.

PowerShell
Get-ChildItem -LiteralPath C:\ -Recurse -File -Force |
    Sort-Object -Property Length -Descending |
    Select-Object -First 10

The output has the same columns. Hidden files show an h in the Mode column1.

Search one folder for one file type

-Filter keeps only the files that match a pattern, such as *.log. The FileSystem provider applies the filter while it gets the files, which is more efficient than filtering afterward1. Replace C:\Test with your folder.

PowerShell
Get-ChildItem -LiteralPath C:\Test -Recurse -File -Filter '*.log' |
    Sort-Object -Property Length -Descending |
    Select-Object -First 5

It returns the five largest .log files in that folder and its subfolders1,2,3.

Use Sort-Object -Top in PowerShell 7

-Top gets a number of objects from the start of the sorted list, so you don't need Select-Object2.

PowerShell
Get-ChildItem -LiteralPath C:\ -Recurse -File |
    Sort-Object -Property Length -Descending -Top 10

It returns the same 10 files as the first example. -Top was introduced in PowerShell 6.0, so it isn't available in Windows PowerShell 5.12.

Common errors

Folders appear in the results. Add -File. Without it, Get-ChildItem lists folders as well as files1.

Hidden files are missing. Get-ChildItem doesn't show hidden items by default. Add -Force1.

Some folders are skipped. -Force gets hidden and system files, but it doesn't override security restrictions1. Files in folders your account can't open won't be listed.

-Top is not accepted. Windows PowerShell 5.1 has no -Top parameter, because it arrived in PowerShell 6.02. Use Select-Object -First instead3.

-Path with -Recurse returns odd results. With -Recurse, Get-ChildItem searches for the last part of the -Path value in every subfolder. Use -LiteralPath for the folder, and -Filter for the pattern you want to match1.

Questions

How do I check one folder without its subfolders?
Leave out -Recurse. Without it, Get-ChildItem gets only the items in the folder you name1. To go a few levels down instead, use -Depth, which sets how many subfolder levels to include1.
What unit is the Length column in?
Length is the file size1. The Select-Object docs divide Length by 1KB to show a size in kilobytes3. In PowerShell, 1KB is 1,024 and 1MB is 1,024 squared4.
How do I list the smallest files instead?
Leave out -Descending. Sort-Object sorts in ascending order by default, so the smallest files come first2.
Are there shorter names for these cmdlets?
Yes. On Windows, Get-ChildItem has the aliases dir, gci and ls1. Sort-Object has the alias sort on Windows2, and Select-Object has the alias select3.

26 Sept 2026: Published.

Sources

  1. Get-ChildItem (Microsoft.PowerShell.Management), Microsoft Learn. Accessed 26 Sept 2026.
  2. Sort-Object (Microsoft.PowerShell.Utility), Microsoft Learn. Accessed 26 Sept 2026.
  3. Select-Object (Microsoft.PowerShell.Utility), Microsoft Learn. Accessed 26 Sept 2026.
  4. about_Numeric_Literals, Microsoft Learn. Accessed 26 Sept 2026.