Skip to content
Quadstronaut edited this page Jun 7, 2026 · 1 revision

Learn/ — Annotated PowerShell Tutorials

The Learn/ files are annotated transcriptions of the LearnXInYMinutes PowerShell guide (CC BY-SA 3.0, original by Wouter Van Schandevijl and Andrew Ryan Davis). They add deep commentary on why PowerShell works the way it does — especially for developers coming from Python, Bash, C#, or JavaScript.


Recommended Reading Order

Work through these files in order. Each builds on the previous.

# File Key concepts
1 01-Basics/01-datatypes-and-operators.ps1 Numbers, Banker's rounding, strings, escape characters, booleans, comparison operators (-eq, -lt), logical operators (-and, -or)
2 01-Basics/02-variables-and-collections.ps1 The $ sigil, fixed-size arrays, ArrayList, hashtables, ordered hashtables, splatting, tuples
3 01-Basics/03-control-flow.ps1 if/elseif/else, switch (no fall-through), foreach vs ForEach-Object, try/catch/finally, -ErrorAction Stop
4 02-Functions/01-functions.ps1 Parameters, implicit return, [CmdletBinding()], BEGIN/PROCESS/END blocks, ValidateSet, splatting
5 03-Modules/01-modules.ps1 Install-Module vs Chocolatey/Scoop, PSGallery, writing modules, dot-sourcing
6 04-Classes/01-classes-and-inheritance.ps1 ::new() vs New-Object, inheritance, $this, static members, enums, flags
7 05-Advanced/01-advanced-topics.ps1 Pipeline objects vs text (Bash comparison), jobs, PSRemoting, & vs Invoke-Expression, execution policy

Concepts Explained in Unusual Depth

These are the things that trip up experienced programmers new to PowerShell. Each is covered with a "why does it work this way?" explanation, not just a code sample.

Data types and operators

  • Banker's rounding[Math]::Round(2.5) returns 2, not 3. PowerShell uses round-half-to-even by default, matching .NET. Use [Math]::Round(2.5, [MidpointRounding]::AwayFromZero) for the behavior you expect.
  • Fixed-size arrays and += — Arrays created with @() are fixed-size; += allocates a new array every time (O(n) per append, O(n²) total). Use [System.Collections.ArrayList] when the size is unknown.
  • -eq on arrays — When the left operand is an array, -eq filters it rather than comparing it. @(1,2,3) -eq 2 returns @(2), not $true.
  • -and/-or instead of &&/|| — PowerShell reserved && and || for pipeline chain operators (PS 7+). In PS 5.1 they're errors. Use -and/-or in conditionals.

Variables and collections

  • The $ sigil — Comes from Unix shell heritage. $ prefixes variable names everywhere they're used, unlike most C-family languages.
  • Backtick as escape — PowerShell uses ` instead of \ because \ is the Windows path separator.
  • Tuples — Provide immutability (safety, intent clarity, thread-safety) when you have a fixed set of values that should never be reassigned.
  • Splatting — Pass a hashtable or array as a parameter bundle using @variable syntax. Avoids long parameter lines; useful for DRY cmdlet calls.

Functions

  • [CmdletBinding()] — Turns a function into an "advanced function" that inherits all common parameters: -Verbose, -Debug, -ErrorAction, -WarningAction, -OutVariable, -WhatIf, -Confirm, etc. Free functionality for free.
  • BEGIN/PROCESS/END blocks — Without PROCESS {}, a function that receives pipeline input processes only the last item. PROCESS {} runs once per pipeline item.

Modules vs dot-sourcing

  • Import-Module vs dot-sourcing (. .\file.ps1) — Import-Module creates a module scope; dot-sourcing runs the file in the current scope, making its functions and variables available directly. Choose based on whether you want isolation.

Advanced topics

  • & vs Invoke-Expression& (call operator) runs a command in a child scope; Invoke-Expression runs a string as code in the current scope. iex is dangerous with untrusted input and rarely necessary.
  • Pipeline objects vs Bash text — In Bash, pipelines pass text. In PowerShell, pipelines pass .NET objects with full property access, sorting, and filtering without parsing. This is the single biggest conceptual shift for Bash users.
  • Jobs (Start-Job) — Run commands asynchronously in a separate process. Results are available via Receive-Job. Useful for background work without blocking the terminal.
  • PSRemoting — Execute commands on remote machines via Invoke-Command -ComputerName. Requires WinRM configured on the target.

How to Use These Files

# Open in VS Code for syntax highlighting + inline comments
code .\Learn\01-Basics\01-datatypes-and-operators.ps1

# Or open in the ISE
ise .\Learn\01-Basics\01-datatypes-and-operators.ps1

# Run a specific section by selecting it and pressing F8 in ISE / VS Code PowerShell extension

The files are designed to be read more than run. Run sections in isolation to see the output — running an entire file may produce side effects or confusing interleaved output.


Attribution

Learn/ files are based on the LearnXInYMinutes PowerShell guide by Wouter Van Schandevijl and Andrew Ryan Davis, licensed CC BY-SA 3.0. Annotations and commentary by Quadstronaut.

Clone this wiki locally