# Exercise: Today's Weather Report

Answer a running club's three morning questions (will it rain, how warm will it be, when can we run dry) from saved copies of a real weather API's answers, with Invoke-RestMethod's objects, query parameters and the pipeline, saving each answer as a small report that a Pester check reads.

Journeyman · PowerShell · Updated November 10, 2026

A running club meets at Green Lake in Seattle, and every morning someone asks the group chat the same three things: will it rain, how warm will it be, and when is the best time to run? A weather API answers all three, and with PowerShell you can turn its answer into a report in a handful of lines. This is the everyday shape of a lot of work: an office manager's morning numbers, a developer's status check, an analyst's daily download. You'll write seven small reports, and a check tells you which are right.

## Get the exercise code

Open this lesson's GitHub repository, [github.com/ask-codey/exercise-powershell-todays-weather-report](https://github.com/ask-codey/exercise-powershell-todays-weather-report), 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:

- `saved`: three real answers from the National Weather Service's API, saved on 9 November 2026: `points.json` for the spot by the lake, `forecast.json` with the week's 14 forecast periods, and `forecast-celsius.json`, the same forecast in Celsius.
- `README.md`: the seven tasks.
- `Check.Tests.ps1`: the check that reads your reports. You don't need to change it.

## Why saved copies

A forecast changes every hour, so a check can't know today's right answers. The saved copies are the answers the API gave when the exercise was made, and they turn into the same objects `Invoke-RestMethod` gave then. The exercise and its check work without the internet:

```powershell
(Get-Content saved\forecast.json -Raw | ConvertFrom-Json).properties.periods | Select-Object -First 2 name, temperature, shortForecast
```

```text
name      temperature shortForecast
----      ----------- -------------
Overnight          43 Cloudy
Monday             56 Cloudy then Light Rain
```

`Get-Content -Raw` reads the whole file as one piece of text, and `ConvertFrom-Json` turns it into objects, as *JSON: ConvertFrom-Json and ConvertTo-Json* showed. When you're online, the README shows the same line on today's live forecast.

## What to do

Open PowerShell 7 in the exercise folder, the one with `Check.Tests.ps1` in it. Run every command from there, and save every report there too, not inside `saved`. Then do the seven tasks in the folder's `README.md`:

1. **Where's the forecast?** The forecast address from `saved\points.json`, in `forecast-url.txt`.
2. **The next few hours in one line.** The first period's `detailedForecast`, in `today.txt`.
3. **The week at a glance.** Every period's `name`, `temperature` and `shortForecast` as a table, in `week.txt`.
4. **When can the club run dry?** The names of the periods with less than a 20% chance of rain, in order, in `dry.txt`.
5. **The warmest.** The warmest period's name, in `warmest.txt`.
6. **Ask for Celsius.** The forecast address with the query parameter `units=si`, in `celsius-url.txt`.
7. **The warmest, in Celsius.** That period's temperature from `saved\forecast-celsius.json`, in `celsius.txt`.

## 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 seven 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.

Made a mistake? Write the report again: `Set-Content` and `Out-File` replace what a file held. 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

- **Dots go down a level at a time.** `.properties.forecast` in the points answer, `.properties.periods` in the forecast, as *APIs as Objects: Invoke-RestMethod* shows.
- **Only the values.** `Select-Object -ExpandProperty name` gives names alone, one a line; `Set-Content` saves them.
- **A table goes into a file with `Out-File` or `>`.** `Set-Content` after `Select-Object` writes `@{name=…}` lines instead, as *Tables and Lists: Format-Table and Format-List* explains.
- **A property inside a property needs braces.** The chance of rain is `$_.probabilityOfPrecipitation.value`, inside `Where-Object { … }`, as *Filtering: Where-Object and Comparisons* shows.
- **Sort first, then take the first one.** *Sorting: Sort-Object* shows why the order of the steps matters.
- **Query parameters go after a `?`.** *APIs as Objects: Invoke-RestMethod* shows how to write one, and why the whole address goes in quotes.

## When you're done

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

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

Now look at `dry.txt` beside `week.txt`. If you were in the club, which morning would you pick for the long run?

## 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-todays-weather-report`), 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-todays-weather-report.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-todays-weather-report.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-todays-weather-report`, 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

A weather report, a price list, a status page: once an API's answer is objects, a morning report is a handful of lines, and the same lines work again tomorrow on tomorrow's data.

## Key terms

- [Invoke-RestMethod](https://www.ask-codey.com/glossary/invoke-restmethod)
- [API](https://www.ask-codey.com/glossary/api)
- [JSON](https://www.ask-codey.com/glossary/json)
- [Query String](https://www.ask-codey.com/glossary/query-string)

## Related

- [APIs as Objects: \`Invoke-RestMethod\`](https://www.ask-codey.com/lessons/powershell-invoke-restmethod)
- [Pages and Downloads: \`Invoke-WebRequest\`](https://www.ask-codey.com/lessons/powershell-invoke-webrequest)
- [JSON: ConvertFrom-Json and ConvertTo-Json](https://www.ask-codey.com/lessons/powershell-json)
- [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)

Source: https://www.ask-codey.com/lessons/exercise-powershell-todays-weather-report
