---
title: "Find large files in PowerShell with Get-ChildItem and Sort-Object"
canonical: https://saasranked.com/guides/find-large-files-powershell/
applies_to: Windows PowerShell 5.1, PowerShell 7
checked: 2026-09-26 (against Microsoft's documentation)
updated: 2026-09-26
---

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

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

To find the largest files on a drive, list every file with Get-ChildItem -Recurse -File [1]. Pipe the list to Sort-Object -Property Length -Descending, so the biggest files come first [2]. Then keep the top of the list with Select-Object -First 10 [3]. Length is the file size that Get-ChildItem shows by default [1]. Add -Force to include hidden and system files [1].

## 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 list [1][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 wildcards [1].
- `-Recurse` gets the items in that folder and in all its child folders [1].
- `-File` returns files only. It works in the FileSystem provider [1].
- `-Property Length` sorts on Length, the file size that Get-ChildItem lists by default [1][2].
- `-Descending` sorts from largest to smallest. The default is ascending order [2].
- `-First` keeps that number of objects from the start of the list [3].

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` instead [1].

## 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 largest [1][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 folder [1].

### 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 1KB [3]. This version divides by 1MB, which PowerShell reads as 1,024 squared [4].

```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 file [2], and Size(MB) is the calculated size [3].

### Include hidden and system files

By default, Get-ChildItem doesn't show hidden items. Add `-Force` to get hidden and system files too [1].

```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 column [1].

### 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 afterward [1]. 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 subfolders [1][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-Object [2].

```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.1 [2].

## Common errors

**Folders appear in the results.** Add `-File`. Without it, Get-ChildItem lists folders as well as files [1].

**Hidden files are missing.** Get-ChildItem doesn't show hidden items by default. Add `-Force` [1].

**Some folders are skipped.** `-Force` gets hidden and system files, but it doesn't override security restrictions [1]. 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.0 [2]. Use `Select-Object -First` instead [3].

**`-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 match [1].

## 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 name [1]. To go a few levels down instead, use -Depth, which sets how many subfolder levels to include [1].

**What unit is the Length column in?** Length is the file size [1]. The Select-Object docs divide Length by 1KB to show a size in kilobytes [3]. In PowerShell, 1KB is 1,024 and 1MB is 1,024 squared [4].

**How do I list the smallest files instead?** Leave out -Descending. Sort-Object sorts in ascending order by default, so the smallest files come first [2].

**Are there shorter names for these cmdlets?** Yes. On Windows, Get-ChildItem has the aliases dir, gci and ls [1]. Sort-Object has the alias sort on Windows [2], and Select-Object has the alias select [3].

## Sources

1. [Get-ChildItem (Microsoft.PowerShell.Management)](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-childitem), Microsoft Learn, accessed 2026-09-26
2. [Sort-Object (Microsoft.PowerShell.Utility)](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/sort-object), Microsoft Learn, accessed 2026-09-26
3. [Select-Object (Microsoft.PowerShell.Utility)](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/select-object), Microsoft Learn, accessed 2026-09-26
4. [about_Numeric_Literals](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_numeric_literals), Microsoft Learn, accessed 2026-09-26

Checked against Microsoft's documentation on 26 Sept 2026.
