liveBook · Manning

Chapter 12: Filtering and comparisons

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

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

After this chapter you will be able to

What it builds on

Section by section

Introduction

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

Key terms: output, narrow down the results, match a pattern

12.1 Making the shell give you just what you need

This section introduces two ways to narrow PowerShell results and explains why filtering at the retrieving cmdlet is preferred when possible.

Key terms: filtering, filter left, early filtering, Get-Process, Get-ChildItem, -Path, Where-Object

12.2 Filtering left

This section explains why to filter early in a PowerShell command and when to use Where-Object instead of a cmdlet’s own filtering options.

Key terms: filter left, filtering criteria, cmdlets, Get-Process, Name, Id, Where-Object, where, pipeline

12.3 Using comparison operators

This section explains how PowerShell comparison and logical operators test relationships between values and return True or False.

Key terms: comparison operator, Boolean, -eq, -ne, -ge, -le, -and, -or, -not, subexpression

12.4 Filtering objects out of the pipeline

This section explains how Where-Object filters pipeline objects with a comparison, how to find the right property names, and when its simplified syntax can be used.

Key terms: Where-Object, pipeline, True, False, $_, WorkingSet, Get-Member, property, PM(MB), PM

12.5 Using the iterative command-line model

This section teaches readers to build a PowerShell pipeline one step at a time, checking each result before extending the command.

Key terms: iterative command-line model, pipeline, filter left, Where-Object, Select-Object, virtual memory, -last, Help, Get-Command, wildcard search

12.6 Common points of confusion

Introduces a review of two common points of confusion about Where-Object.

12.6.1 Filter left, please

This subsection explains why filtering should happen as early in a pipeline and as close to the data source as possible.

Key terms: filter left, Where-Object, source of the data, PowerShell remoting

12.6.2 When $_ is allowed

Explains what $_ refers to in a pipeline and how its meaning changes when a parenthetical pipeline runs inside a larger command.

Key terms: $_ placeholder, pipeline, parenthetical command, nested pipelines, Get-Content, Where-Object, Get-Process, WorkingSet

12.7 Lab

12.8 Lab answers

12.9 Further exploration

This section suggests filtering exercises using familiar commands and cautions against using Where-Object in every case.

Key terms: filtering, Where-Object, Get-Command, Test-Connection

Where this is used later

Concepts explained in this chapter

← Chapter 11: Formatting: And why it’s done on the right Chapter 13: Remote control: One-to-one and one-to-many →

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.