Um momento
0x00Lesson 1 of 17

Meet PowerShell

Learn what PowerShell is, how its Verb-Noun commands work, and print your first output.

20 min 7-question quiz 2 code exercises
By the end of this lesson you can
  • Explain what makes PowerShell different from text-based shells
  • Read a command as a Verb-Noun cmdlet with parameters
  • Print text with Write-Output, strings and the -f format operator

Welcome to Emberfall Dragon Sanctuary. Eight dragons, three keepers, one very old castle full of servers - and you’re the new automation keeper. Feeding schedules, enclosure files, health reports: by the end of this track you’ll script all of it.

Your tool is PowerShell, a command-line shell and a scripting language from Microsoft, built on .NET. It runs on Windows, macOS and Linux, and it’s how most Windows, Azure and Microsoft 365 administration gets done.

Its big idea: commands pass objects, not text. When you list files, you don’t get lines to cut apart - you get file objects with a Name, a Length and a LastWriteTime you can sort, filter and do arithmetic on directly.

Cmdlets: Verb-Noun commands

PowerShell’s built-in commands are called cmdlets (“command-lets”), and they’re all named Verb-Noun: Get-Date, Set-Location, New-Item, Remove-Item, Sort-Object. Once you know the pattern you can often guess a command’s name before you look it up.

1Get-ChildItem -Path C:\Dragons -Filter *.txt -Recurse
2#    │           │               │             └── a switch parameter (no value)
3#    │           │               └── parameter with a value
4#    │           └── parameter name (always starts with -)
5#    └── cmdlet: Verb-Noun

Parameter names are case-insensitive and can be shortened as long as they stay unambiguous (-Rec for -Recurse). Many common cmdlets also have short aliases: ls, dir and gci all mean Get-ChildItem; cd is Set-Location; cat is Get-Content. Aliases are great at the prompt - in scripts, spell out the full name so others can read it.

Your first output

Anything a command produces that isn’t captured goes to the output, which the console prints. Write-Output sends objects to the output - and a bare value on a line does exactly the same thing, so most scripts just write the value. Press Run, then Edit and experiment.

hello.ps1
1Write-Output 'Welcome to Emberfall!'
2'A bare string is output too'
36 * 7
4'Dragons: ' + 8
5"Wingspan: {0} m, age: {1}" -f 12, 140
6'{0,-8}|{1,5}|' -f 'Ember', 'grumpy'
Output
Welcome to Emberfall!
A bare string is output too
42
Dragons: 8
Wingspan: 12 m, age: 140
Ember   |grumpy|

The last two lines use the format operator -f. The string on its left has numbered placeholders, {0}, {1}, ... filled from the values on its right. Add a width after a comma: {0,-8} pads to 8 characters, left-aligned, and {1,5} right-aligns in 5 - perfect for tidy tables.

You may also meet Write-Host. It paints text straight onto the screen instead of sending it to the output, so nothing can capture, pipe or save it. Use it only for messages meant purely for a human.

Try it

Read the command line

Each item shows a command with one part in brackets. What role does that part play?

0 of 7 sortedScore 0/0
  • “[Get-ChildItem] -Path C:\Dragons”

  • “Get-ChildItem [-Path] C:\Dragons”

  • “Get-ChildItem -Path [C:\Dragons]”

  • “Get-Date [-Format] yyyy-MM-dd”

  • “Get-Date -Format [yyyy-MM-dd]”

  • “[Sort-Object] -Property Wingspan -Descending”

  • “Sort-Object -Property Wingspan [-Descending]”

Key takeaways

  • PowerShell is a shell and scripting language on .NET whose commands pass objects, not text.

  • Cmdlets are named Verb-Noun and take -Parameter value arguments; switches need no value.

  • Uncaptured values become output; Write-Output is the explicit way to say so.

  • The -f operator fills {0}, {1}... placeholders, with optional widths like {0,-8}.

Lesson quiz

7 questions · pass with 5 correct · up to 50 XP

Passing this quiz completes the lesson and keeps your streak going. Questions you miss come back in review sessions later.

Practice: write PowerShell scripts

Write a script in the editor and run it for real against sample input, which is piped into your script as $input. Scripts run on PowerShell 6.2 through Try It Online (tio.run), a free public service, so these exercises avoid PowerShell 7-only syntax; your script and test input are sent there.

Exercise 1

Paint the sanctuary sign

+25 XP

Print exactly these three lines:

*** EMBERFALL DRAGON SANCTUARY ***
Dragons in residence: 8
Please do not feed the wyrms
  • Prints the sign
script.ps1
Loading editor…

Lessons teach PowerShell 7; your script runs on PowerShell 6.2 via Try It Online (tio.run), a free public service, so stick to syntax that works there. Test input is piped into your script as $input. Your script and test input are sent to that service.

Exercise 2

Wingspan board

+25 XP

Use the -f operator to print a board of wingspans: the name left-aligned in 10 characters, then the wingspan right-aligned in 3, then m:

Ember      12 m
Mossback    4 m
Skyla      15 m
  • Prints the board
script.ps1
Loading editor…

Lessons teach PowerShell 7; your script runs on PowerShell 6.2 via Try It Online (tio.run), a free public service, so stick to syntax that works there. Test input is piped into your script as $input. Your script and test input are sent to that service.

Questions about this lesson

Stuck? Ask. Figured something out? Share it. Explaining is one of the best ways to learn.

Loading posts…

Gostou da aula? 😆👍
Apoie nosso trabalho com uma doação: