PowerShell Genie
Practice Find large log files

Find large log files

Exercise 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

Return .log files larger than 10 MiB, largest first.

The task

A log folder is using more space than expected. Identify the large files before deciding whether they can be archived.

Target

Return .log files larger than 10 MiB, largest first.

What the result tells you

Length is bytes. In PowerShell, 10MB means 10 × 1024 × 1024 bytes. Filtering by extension prevents unrelated large files from entering this report.

Verify the result

Run the source by itself and inspect the sample objects. Add each filter separately, then check the final properties and order.

The browser uses a small fictional dataset. Real results depend on the host, module, account and target environment.

Why inspect file size before removing a log?

Choose an answer, then check your reasoning.

Worked solution

Worked solution

Reveal one approach
1PS> Get-ChildItem -File | Where-Object Extension -eq '.log' | Where-Object Length -gt 10MB | Sort-Object Length -Descending | Select-Object Name, Length

Related reference

Read the command and platform requirements
Next exercise

Try it in the lab

Write your pipeline below and run it against the fictional sample data, then check your result against the expected answer.

Interactive simulation · fictional data
Genie guideFind large log files

Return .log files larger than 10 MiB, largest first.