# Exercise: The Ten Biggest Files

Find out what's filling a full laptop's 24 made-up files with the pipeline (a count, the ten biggest, the big videos, the files of each type and a table of sizes in KB, each saved as a report) and rename its screenshots with ForEach-Object, while a Pester check tells you which answers are right.

Apprentice · PowerShell · Operating System · Updated November 10, 2026

A cousin's old laptop is full, and before anyone deletes anything, you've been asked what's taking up the space. That's the job an IT help-desk tech gets every week, and the pipeline answers it in a handful of lines. You'll answer six questions about a copy of the laptop's files, save each answer as a small report, and a check tells you which answers are right.

## Get the exercise code

Open this lesson's GitHub repository, [github.com/ask-codey/exercise-powershell-the-ten-biggest-files](https://github.com/ask-codey/exercise-powershell-the-ten-biggest-files), also linked from the **Exercise** box beside the lesson. Click **Code**, then **Download ZIP**, and unzip it into your `terminal-practice` folder. Or clone it with Git.

The folder holds:

- `old-laptop`: the laptop's 24 made-up files in five folders, about 7 MB in all. They hold only the letter x, over and over, so each has a real size but nothing to open.
- `README.md`: the six tasks.
- `Check.Tests.ps1`: the check that reads your reports and looks at the `Pictures` folder. You don't need to change it.

## What to do

Open PowerShell 7 in the exercise folder, the one with `Check.Tests.ps1` in it, and look around first:

```powershell
Get-ChildItem old-laptop
```

```text
    Directory: C:\Users\Sam\terminal-practice\exercise-powershell-the-ten-biggest-files\old-laptop

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d----           9/14/2026  6:30 PM                Documents
d----           9/14/2026  6:30 PM                Downloads
d----           9/14/2026  6:30 PM                Music
d----           9/14/2026  6:30 PM                Pictures
d----           9/14/2026  6:30 PM                Videos
```

Your dates will be the day you unzipped it. Then do the six tasks in the folder's `README.md`. Run every command from the exercise folder, and save every report there too, beside `Check.Tests.ps1`, not inside `old-laptop`:

1. **How many files?** The number of files in `old-laptop` and every folder inside it, in `count.txt`.
2. **The ten biggest.** Their names, biggest first, one a line, in `biggest.txt`.
3. **The big videos.** The names of the `.mp4` files over 500 KB, smallest first, in `big-videos.txt`.
4. **What kinds of files?** Each extension's Count and Name, the biggest group first, in `types.txt`.
5. **Sizes people can read.** The ten biggest as a table with `Name` and a column of your own, `SizeKB`, rounded to whole kilobytes, in `sizes.txt`.
6. **Tidy the screenshots.** Every `Screenshot_` file in `old-laptop\Pictures` renamed to start with `screenshot-`, with one ForEach-Object, rehearsed with `-WhatIf` first.

## Check your work

The check uses Pester, PowerShell's test tool. If you haven't installed it yet, install it once:

```powershell
Install-PSResource Pester
```

Then, from the exercise folder:

```powershell
Invoke-Pester
```

At first all six tests fail. That's expected: each task you finish turns its test green. A failing test says which task it is, what it expected and what it found. If test 3 says it found `concert-clip.mp4` too, read the hints below.

Made a mistake? Write the report again: `Set-Content` and `Out-File` replace what a file held, as *Writing to Files: Set-Content, Add-Content and >* showed. To start over, download the exercise again.

If PowerShell says the check can't be loaded because running scripts is disabled or the file is not digitally signed, Windows has marked the downloaded files as coming from the internet. From the exercise folder, run `Get-ChildItem -Recurse | Unblock-File` once, then `Invoke-Pester` again. *Why a Script Won't Run: The Execution Policy*, in Module 5, explains what that does.

## Hints

- **One step at a time.** Build each pipeline the way *The Pipeline: |* does: run the first command, look, add the next step. Save it to a file only when the screen shows the right answer.
- **Only the names.** `Select-Object -ExpandProperty Name` gives names alone, one a line. A plain `Select-Object Name` writes a table with a heading, as *Picking Columns: Select-Object* shows.
- **Sort first, then take the top ten.** *Sorting: Sort-Object* shows why the order of the steps matters.
- **500 KB is not 500,000.** PowerShell's `KB` is 1,024 bytes, so `500KB` is 512,000 bytes. *Filtering: Where-Object and Comparisons* has the comparisons.
- **Only the count and name of each group.** *Counting and Grouping: Measure-Object and Group-Object* shows the parameter that leaves out the files.
- **Round to whole kilobytes.** *Columns You Make Yourself: Calculated Properties* shows `[math]::Round`; with no second number, it rounds to a whole number.
- **`-WhatIf` inside the braces.** *Doing Something to Each: ForEach-Object* shows where it goes.

## When you're done

Every test is green, and Pester's last line says:

```text
Tests Passed: 6, Failed: 0, Skipped: 0, Inconclusive: 0, NotRun: 0
```

Now look at `types.txt` and `sizes.txt` side by side. Which kind of file would you look at first, if you had to free up space on that laptop?

## Submit your exercise

The exercise is how you finish this lesson. When your work is done, put it on GitHub in a repo of your own, then submit that repo's address here.

1. On GitHub, click **+**, then **New repository**. Name it (for example `exercise-powershell-the-ten-biggest-files`), choose **Public**, and click **Create repository**. Leave out the README: your folder already has one.
2. In a terminal in your exercise folder (PowerShell works), send your work to your new repo. If you downloaded the ZIP:

   ```powershell
   git init -b main
   git add .
   git commit -m "My solution"
   git remote add origin https://github.com/your-name/exercise-powershell-the-ten-biggest-files.git
   git push -u origin main
   ```

   If you cloned the starter instead, point your copy at your own repo, then commit and push:

   ```powershell
   git remote set-url origin https://github.com/your-name/exercise-powershell-the-ten-biggest-files.git
   git add .
   git commit -m "My solution"
   git push -u origin main
   ```

3. Paste your repo's address, such as `https://github.com/your-name/exercise-powershell-the-ten-biggest-files`, into **Submit your exercise** on this page. The site checks that the repo is public and holds your commits, and then the lesson is complete.

Changed something after you submitted? Push it, and submit again: your latest submission is the one that counts.

## So what

"What's filling this drive?" is a question you'll be asked, and now you can answer it with facts: how many files, the biggest, and which kind takes the most room.

## Key terms

- [Pipeline](https://www.ask-codey.com/glossary/pipeline)
- [Where-Object](https://www.ask-codey.com/glossary/where-object)
- [Sort-Object](https://www.ask-codey.com/glossary/sort-object)
- [Measure-Object](https://www.ask-codey.com/glossary/measure-object)
- [Group-Object](https://www.ask-codey.com/glossary/group-object)
- [ForEach-Object](https://www.ask-codey.com/glossary/foreach-object)
- [Calculated Property](https://www.ask-codey.com/glossary/calculated-property-powershell)

## Related

- [The Pipeline: |](https://www.ask-codey.com/lessons/powershell-the-pipeline)
- [Filtering: Where-Object and Comparisons](https://www.ask-codey.com/lessons/powershell-where-object)
- [Sorting: Sort-Object](https://www.ask-codey.com/lessons/powershell-sort-object)
- [Counting and Grouping: Measure-Object and Group-Object](https://www.ask-codey.com/lessons/powershell-measure-and-group)
- [Doing Something to Each: ForEach-Object](https://www.ask-codey.com/lessons/powershell-foreach-object)
- [Columns You Make Yourself: Calculated Properties](https://www.ask-codey.com/lessons/powershell-calculated-properties)

Source: https://www.ask-codey.com/lessons/exercise-powershell-the-ten-biggest-files
