liveBook · Manning

What you will learn in Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS

Covers Windows, Linux, and macOS

by Travis Plunk,Tyler Leonhardt,James Petty

Chapter by chapter

Chapter 1: Before you begin

This introduction frames PowerShell as a command-line shell that beginners can start using without learning to script first.

1.1 Why you can no longer afford to ignore PowerShell · 1.1.1 Life without PowerShell · 1.1.2 Life with PowerShell · 1.2 Windows, Linux, and macOS, oh my · 1.3 Is this book for you? · 1.4 How to use this book · 1.4.1 The chapters · 1.4.2 Hands-on labs · 1.4.3 Supplementary materials · 1.4.4 Further exploration · 1.4.5 Above and beyond · 1.5 Setting up your lab environment · 1.6 Installing PowerShell · 1.7 Contacting us · 1.8 Being immediately effective with PowerShell

What you learn in chapter 1 →

Chapter 2: Meet PowerShell

Defines the terms needed to distinguish PowerShell versions and understand the difference between a shell and a terminal.

2.1 PowerShell on Windows · 2.2 PowerShell on macOS · 2.2.1 Installation on macOS · 2.3 PowerShell on Linux (Ubuntu 18.04) · 2.3.1 Installation on Ubuntu 18.04 · 2.4 Visual Studio Code and the PowerShell extension · 2.4.1 Installing Visual Studio Code and the PowerShell extension · 2.4.2 Getting familiar with Visual Studio Code · 2.4.3 Customizing Visual Studio Code and the PowerShell extension · 2.5 It’s typing class all over again · 2.6 What version is this? · 2.7 Lab

What you learn in chapter 2 →

Chapter 3: Using the help system

Introduces PowerShell’s help system as a discoverability feature that makes its commands easier to learn.

3.1 The help system: How you discover commands · 3.2 Updatable help · 3.3 Asking for help · 3.4 Using help to find commands · 3.5 Interpreting the help · 3.5.1 Parameter sets and common parameters · 3.5.2 Optional and mandatory parameters · 3.5.3 Positional parameters · 3.5.4 Parameter values · 3.5.5 Finding command examples · 3.6 Accessing “about” topics · 3.7 Accessing online help · 3.8 Lab · 3.9 Lab answers

What you learn in chapter 3 →

Chapter 4: Running commands

The introduction positions running commands as the beginner’s starting point for PowerShell, despite the advanced scripting examples often found online.

4.1 Let’s talk security · 4.1.1 Execution policy · 4.2 Not scripting, but running commands · 4.3 The anatomy of a command · 4.4 The cmdlet naming convention · 4.5 Aliases: Nicknames for commands · 4.6 Taking shortcuts · 4.6.1 Truncating parameter names · 4.6.2 Using parameter name aliases · 4.6.3 Using positional parameters · 4.7 Support for external commands · 4.8 Dealing with errors · 4.9 Common points of confusion · 4.9.1 Typing cmdlet names · 4.9.2 Typing parameters · 4.10 Lab · 4.11 Lab answers

What you learn in chapter 4 →

Chapter 5: Working with providers

Introduces providers as PowerShell’s way to present specialized data stores as drives for easier viewing and management.

5.1 What are providers? · 5.2 Understanding how the filesystem is organized · 5.3 Navigating the filesystem · 5.4 Using wildcards and literal paths · 5.5 Working with other providers · 5.5.1 Windows Registry · 5.6 Lab · 5.7 Lab answers

What you learn in chapter 5 →

Chapter 6: The pipeline: Connecting commands

The introduction contrasts ordinary command execution with PowerShell’s ability to connect commands in one-line sequences.

6.1 Connecting one command to another: Less work for you · 6.2 Exporting to a file · 6.2.1 Exporting to CSV · 6.2.2 Exporting to JSON · 6.2.3 Exporting to XML · 6.2.4 Out-File · 6.2.5 Comparing files · 6.3 Piping to a file · 6.4 Converting to HTML · 6.5 Using cmdlets that modify the system: Killing processes · 6.6 Common points of confusion · 6.7 Lab · 6.8 Lab answers

What you learn in chapter 6 →

Chapter 7: Adding commands

Introduces PowerShell’s extensibility through its growing set of commands for Azure products.

7.1 How one shell can do everything · 7.2 Extensions: Finding and installing modules · 7.3 Extensions: Finding and adding modules · 7.4 Command conflicts and removing extensions · 7.5 Playing with a new module · 7.6 Common points of confusion · 7.7 Lab · 7.8 Lab answers

What you learn in chapter 7 →

Chapter 8: Objects: Data by another name

The introduction emphasizes that objects are central to PowerShell and directs readers to a starting section based on their programming experience.

8.1 What are objects? · 8.2 Understanding why PowerShell uses objects · 8.3 Discovering objects: Get-Member · 8.4 Using object attributes, or properties · 8.5 Using object actions, or methods · 8.6 Sorting objects · 8.7 Selecting the properties you want · 8.8 Objects until the end · 8.9 Common points of confusion · 8.10 Lab · 8.11 Lab answers

What you learn in chapter 8 →

Chapter 9: A practical interlude

Introduces a real-world exercise that applies earlier PowerShell knowledge and models how to work out a solution independently.

9.1 Defining the task · 9.2 Finding the commands · 9.3 Learning to use the commands · 9.4 Tips for teaching yourself · 9.5 Lab · 9.6 Lab answer

What you learn in chapter 9 →

Chapter 10: The pipeline, deeper

This introduction illustrates how a PowerShell pipeline can accomplish a multi-step task in one line and previews a deeper look at passing data between commands.

10.1 The pipeline: Enabling power with less typing · 10.2 How PowerShell passes data down the pipeline · 10.3 Plan A: Pipeline input ByValue · 10.4 Plan B: Pipeline input ByPropertyName · 10.5 When things don’t line up: Custom properties · 10.6 Working with Azure PowerShell · 10.7 Parenthetical commands · 10.8 Extracting the value from a single property · 10.9 Lab · 10.10 Lab answers · 10.11 Further exploration

What you learn in chapter 10 →

Chapter 11: Formatting: And why it’s done on the right

This introduction recaps how object properties and PowerShell’s defaults affect the output readers have seen so far.

11.1 Formatting: Making what you see prettier · 11.2 Working with the default formatting · 11.3 Formatting tables · 11.4 Formatting lists · 11.5 Formatting wide lists · 11.6 Creating custom columns and list entries · 11.7 Going out: To a file or to the host · 11.8 Another out: GridViews · 11.9 Common points of confusion · 11.9.1 Always format right · 11.9.2 One type of object at a time, please · 11.10 Lab · 11.11 Lab answers · 11.12 Further exploration

What you learn in chapter 11 →

Chapter 12: Filtering and comparisons

The chapter introduces filtering as a way to narrow broad shell output to the items you want.

12.1 Making the shell give you just what you need · 12.2 Filtering left · 12.3 Using comparison operators · 12.4 Filtering objects out of the pipeline · 12.5 Using the iterative command-line model · 12.6 Common points of confusion · 12.6.1 Filter left, please · 12.6.2 When $_ is allowed · 12.7 Lab · 12.8 Lab answers · 12.9 Further exploration

What you learn in chapter 12 →

Chapter 13: Remote control: One-to-one and one-to-many

Introduces PowerShell remoting as a shell-wide way to run commands on other computers without requiring every cmdlet to provide its own remote-connection parameter.

13.1 The idea behind remote PowerShell · 13.1.1 Remoting on Windows devices · 13.1.2 Remoting on macOS and Linux devices · 13.1.3 Cross-platform remoting · 13.2 Setting up PSRP over SSH · 13.2.1 macOS and Linux · 13.2.2 Setting up SSH on Windows · 13.3 PSRP over SSH overview · 13.4 WinRM overview · 13.5 Using Enter-PSSession and Exit-PSSession for one-to-one remoting · 13.6 Using Invoke-Command for one-to-many remoting · 13.7 Differences between remote and local commands · 13.7.1 Deserialized objects · 13.7.2 Local vs. remote processing · 13.8 But wait, there’s more · 13.9 Common points of confusion · 13.10 Lab · 13.11 Lab answers · 13.12 Further exploration

What you learn in chapter 13 →

Chapter 14: Multitasking with background jobs

Introduces PowerShell’s ability to do more than one thing at a time, especially for long-running work involving multiple computers.

14.1 Making PowerShell do multiple things at the same time · 14.2 Synchronous vs. asynchronous · 14.3 Creating a process job · 14.4 Creating a thread job · 14.5 Remoting, as a job · 14.6 Jobs in the wild · 14.7 Getting job results · 14.8 Working with child jobs · 14.9 Commands for managing jobs · 14.10 Common points of confusion · 14.11 Lab · 14.12 Lab answers

What you learn in chapter 14 →

Chapter 15: Working with many objects, one at a time

This introduction frames PowerShell administration as work that often needs to be repeated across multiple targets.

15.1 The preferred way: “Batch” cmdlets · 15.2 The CIM way: Invoking methods · 15.3 The backup plan: Enumerating objects · 15.3.1 Making the cmdlets work for you · 15.4 Let’s speed things up · 15.5 Common points of confusion · 15.5.1 Which way is the right way? · 15.5.2 Diminishing returns of Parallel ForEach · 15.5.3 Method documentation · 15.5.4 ForEach-Object confusion · 15.6 Lab · 15.7 Lab answers

What you learn in chapter 15 →

Chapter 16: Variables: A place to store your stuff

Introduces variables as a way to keep PowerShell objects for later use, including outside long scripts.

16.1 Introduction to variables · 16.2 Storing values in variables · 16.3 Using variables: Fun tricks with quotes · 16.4 Storing many objects in a variable · 16.4.1 Working with single objects in a variable · 16.4.2 Working with multiple objects in a variable · 16.4.3 Other ways to work with multiple objects · 16.4.4 Unrolling properties and methods in PowerShell · 16.5 More tricks with double quotes · 16.6 Declaring a variable’s type · 16.7 Commands for working with variables · 16.8 Variable best practices · 16.9 Common points of confusion · 16.10 Lab · 16.11 Lab answers · 16.12 Further exploration

What you learn in chapter 16 →

Chapter 17: Input and output

The introduction explains why scripts may need user input and more control over displayed output, while limiting these techniques to scripts that interact with people.

17.1 Prompting for, and displaying, information · 17.2 Read-Host · 17.3 Write-Host · 17.4 Write-Output · 17.5 Other ways to write · 17.6 Lab · 17.7 Lab answers · 17.8 Further exploration

What you learn in chapter 17 →

Chapter 18: Sessions: Remote control with less work

The introduction explains why repeatedly opening remote connections is tedious and motivates reusable PowerShell sessions.

18.1 Creating and using reusable sessions · 18.2 Enter-PSSession with session objects · 18.3 Invoke-Command with session objects · 18.4 Implicit remoting: Importing a session · 18.5 Using disconnected sessions · 18.6 Lab · 18.7 Lab answers · 18.8 Further exploration

What you learn in chapter 18 →

Chapter 19: You call this scripting?

The introduction contrasts what administrators can accomplish at the PowerShell command line with the reason to start using simple scripts: avoiding repeated typing.

19.1 Not programming, more like batch files · 19.2 Making commands repeatable · 19.3 Parameterizing commands · 19.4 Creating a parameterized script · 19.5 Documenting your script · 19.6 One script, one pipeline · 19.7 A quick look at scope · 19.8 Lab

What you learn in chapter 19 →

Chapter 20: Improving your parameterized script

The introduction explains that parameters let people run a script without changing its contents.

20.1 Starting point · 20.2 Getting PowerShell to do the hard work · 20.3 Making parameters mandatory · 20.4 Adding parameter aliases · 20.5 Validating parameter input · 20.6 Adding the warm and fuzzies with verbose output · 20.7 Lab · 20.8 Lab answer

What you learn in chapter 20 →

Chapter 21: Using regular expressions to parse text files

The introduction positions regular expressions as an occasional PowerShell tool for parsing text files, such as logs.

21.1 The purpose of regular expressions · 21.2 A regex syntax primer · 21.3 Using regex with -Match · 21.4 Using regex with Select-String · 21.5 Lab · 21.6 Lab answers · 21.7 Further exploration

What you learn in chapter 21 →

Chapter 22: Using someone else’s script

This introduction explains why understanding and reusing other people’s PowerShell scripts matters, even when those scripts are imperfect or contain unfamiliar features.

22.1 The script · 22.1.1 Parameter block · 22.1.2 Process block · 22.2 It’s a line-by-line examination · 22.3 Lab · 22.4 Lab answer

What you learn in chapter 22 →

Chapter 23: Adding logic and loops

Introduces looping as a way to process objects one at a time or execute a block of code repeatedly in PowerShell.

23.1 Foreach and Foreach-Object · 23.1.1 Foreach · 23.1.2 Foreach-Object · 23.1.3 Foreach-Object -Parallel · 23.2 While · 23.3 Do While · 23.4 Lab · 23.5 Lab answers

What you learn in chapter 23 →

Chapter 24: Handling errors

The chapter introduces two ways to retain PowerShell errors for later handling: the automatic $Error variable and the ErrorVariable common parameter.

24.1 Understanding errors and exceptions · 24.2 Bad handling · 24.3 Two reasons for exception handling · 24.4 Handling exceptions · 24.5 Handling exceptions for noncommands · 24.6 Going further with exception handling · 24.7 Lab

What you learn in chapter 24 →

Chapter 25: Debugging techniques

The introduction distinguishes bugs from anticipated errors and frames debugging as finding mistakes in scripts.

25.1 Output everything · 25.2 One line at a time · 25.3 Hey, script, stop right there . . . with breakpoints · 25.4 Lab

What you learn in chapter 25 →

Chapter 26: Tips, tricks, and techniques

This section explains how PowerShell profile scripts customize shell startup and how their location, host, and execution policy affect when they run.

26.1 Profiles, prompts, and colors: Customizing the shell · 26.1.1 PowerShell profiles · 26.1.2 Customizing the prompt · 26.1.3 Tweaking colors · 26.2 Operators: -as, -is, -replace, -join, -split, -contains, -in · 26.2.1 -as and -is · 26.2.2 -replace · 26.2.3 -join and -split · 26.2.4 -contains and -in · 26.3 String manipulation · 26.4 Date manipulation · 26.5 Dealing with WMI dates · 26.6 Setting default parameter values · 26.7 Playing with script blocks · 26.8 More tips, tricks, and techniques

What you learn in chapter 26 →

Chapter 27: Never the end

The chapter introduction encourages readers to continue exploring PowerShell and previews guidance for doing so.

27.1 Ideas for further exploration · 27.2 “Now that I’ve read the book, where do I start?” · 27.3 Other resources you’ll grow to love

What you learn in chapter 27 →

Concepts explained in this book

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.