-
Notifications
You must be signed in to change notification settings - Fork 0
Learn
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.
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 |
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.
-
Banker's rounding —
[Math]::Round(2.5)returns2, not3. 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. -
-eqon arrays — When the left operand is an array,-eqfilters it rather than comparing it.@(1,2,3) -eq 2returns@(2), not$true. -
-and/-orinstead of&&/||— PowerShell reserved&&and||for pipeline chain operators (PS 7+). In PS 5.1 they're errors. Use-and/-orin conditionals.
-
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
@variablesyntax. Avoids long parameter lines; useful for DRY cmdlet calls.
-
[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.
-
Import-Modulevs 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.
-
&vsInvoke-Expression—&(call operator) runs a command in a child scope;Invoke-Expressionruns a string as code in the current scope.iexis 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 viaReceive-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.
# 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 extensionThe 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.
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.