Exercise: Your Practice Folder
Put your first exercise in your practice folder, ask PowerShell four questions about itself, write the answers in my-setup.txt, and install Pester to run your first check.
Novice · PowerShell · Operating System · Updated
Before you explore anything, make sure your setup is ready: PowerShell 7 installed, Windows Terminal opening it every time, and a practice folder where every exercise in this course will live. You'll ask PowerShell four questions about itself, write the answers in a file, and run your first check, a small file of tests that tells you which answers are right.
Get the exercise code
Open this lesson's GitHub repository, github.com/ask-codey/exercise-powershell-your-practice-folder, also linked from the Exercise box beside the lesson. Click Code, then Download ZIP, and unzip it into your terminal-practice folder, the one you made in Setup: Windows Terminal and PowerShell 7. Or clone it with Git.
The folder holds:
my-setup.txt: one line for each question, for your answers.Check.Tests.ps1: the check that reads your answers and looks at your setup. You don't need to change it.README.md: the questions, and the steps below.
What to do
Open PowerShell 7 in the exercise folder. In File Explorer, right-click an empty part of the folder and choose Open in Terminal: a mouse step that starts PowerShell exactly where you need it. Or paste this line, with your own folder's name if it differs (Moving Around: Set-Location, .. and Tab teaches it properly):
Set-Location -Path "$HOME\terminal-practice\exercise-powershell-your-practice-folder"
Then answer the four questions in the folder's README.md. my-setup.txt has a line waiting for each one:
# Write each answer after its number, on the same line. See README.md for the questions.
1)
2)
3)
4)
Write each answer after its number, such as 2) Core, and save the file. Open it with edit my-setup.txt, or in Notepad.
The questions ask for the version of PowerShell you're running, its edition, your user name from your home folder's path, and the shell Windows Terminal opens in a new tab. Every answer comes from a command or a setting in this chapter's lessons.
Check your work
The check uses Pester, PowerShell's test tool. Pester is a module, a package of extra commands, and it comes from the PowerShell Gallery, the public library of PowerShell modules. Install it once:
Install-PSResource Pester
The first time, PowerShell asks whether you're sure you want to install from PSGallery, because a new computer doesn't mark the Gallery as trusted yet. Type Y and press Enter. Pester installs for your user account only, so it doesn't need an administrator window. (Windows PowerShell 5.1 has no Install-PSResource: use PowerShell 7.)
Then, from the exercise folder:
Invoke-Pester
At first the tests fail. That's expected: each answer you write turns its test green, and test 5 turns green when the exercise folder sits inside your practice folder. A failing test names its question and says where to look, for example Expected a value, because question 2 has no answer yet. Run $PSVersionTable.PSEdition, but got $null or empty.
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
- Check which PowerShell you're in. The check has to run in PowerShell 7. PowerShell, Windows PowerShell and the Terminal shows how to ask.
- Copy, don't retype. Select what PowerShell printed and paste it into
my-setup.txt, so a typo can't creep in. - Read the setting's own words. For question 4, write the profile's name exactly as Windows Terminal's settings show it.
- Save before you check.
Invoke-Pesterreads the file as it is on disk.
When you're done
Every test is green, and Pester's last line says:
Tests Passed: 5, Failed: 0, Skipped: 0, Inconclusive: 0, NotRun: 0
Now look at Check.Tests.ps1 in Notepad or edit. You don't need to understand it yet, but find the line that reads your answer to question 2. By Module 7 you'll write checks like this for your own tools.
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.
On GitHub, click +, then New repository. Name it (for example
exercise-powershell-your-practice-folder), choose Public, and click Create repository. Leave out the README: your folder already has one.In a terminal in your exercise folder (PowerShell works), send your work to your new repo. If you downloaded the ZIP:
git init -b main git add . git commit -m "My solution" git remote add origin https://github.com/your-name/exercise-powershell-your-practice-folder.git git push -u origin mainIf you cloned the starter instead, point your copy at your own repo, then commit and push:
git remote set-url origin https://github.com/your-name/exercise-powershell-your-practice-folder.git git add . git commit -m "My solution" git push -u origin mainPaste your repo's address, such as
https://github.com/your-name/exercise-powershell-your-practice-folder, 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
Your tools are ready and your practice folder is in place, and you've run your first check. Every exercise in this course ends the same way: the tests go from red to green.