liveBook · Manning

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

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

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

After this chapter you will be able to

What it builds on

Section by section

Introduction

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

Key terms: automate administration, multiple targets

15.1 The preferred way: “Batch” cmdlets

The section presents cmdlets that act on batches of objects as the preferred way to perform repeated tasks, and shows how -PassThru makes their results visible.

Key terms: batch cmdlets, pipeline, objects, -PassThru, Set-Service, Copy-Item

15.2 The CIM way: Invoking methods

Shows how to find and invoke a CIM object's method across multiple Windows network adapter configurations, then interpret the results.

Key terms: CIM, Win32_NetworkAdapterConfiguration, Get-CimClass, CimClassMethods, EnableDHCP, Invoke-CimMethod, CIM objects, -WhatIf, -Confirm, ReturnValue

15.3 The backup plan: Enumerating objects

This section explains when enumerating objects becomes a fallback and why a cmdlet’s pipeline-input rules can make that fallback necessary.

Key terms: batch cmdlet, enumerate the objects, scripting construct, ByPropertyName, ByValue, Id, Name parameter

15.3.1 Making the cmdlets work for you

This subsection shows how to create multiple vaults by feeding names from a text file to a cmdlet that accepts one name at a time.

Key terms: New-AzKeyVault, ForEach-Object, enumerate, Get-Content, -Process, script block, $_, Name parameter

15.4 Let’s speed things up

This section shows how PowerShell 7’s ForEach-Object -Parallel can shorten work on multiple items and how its throttle limit affects the result.

Key terms: ForEach-Object, -Parallel, Measure-Command, script blocks, throttle limit, ThrottleLimit, Parallel ForEach

15.5 Common points of confusion

This section introduces common sources of confusion in the chapter and points readers to the explanations that follow.

15.5.1 Which way is the right way?

This section compares ways to act on a group of PowerShell objects and explains why no single approach is always right.

Key terms: batch cmdlet, action cmdlet, ForEach-Object, -Parallel

15.5.2 Diminishing returns of Parallel ForEach

This subsection explains why increasing Parallel ForEach’s ThrottleLimit can make work slower rather than faster.

Key terms: Parallel ForEach, ThrottleLimit, context switch, diminishing returns

15.5.3 Method documentation

This subsection explains how to find documentation for an object's methods when PowerShell help does not provide it.

Key terms: Get-Member, TypeName, methods

15.5.4 ForEach-Object confusion

This subsection clarifies how to read and write ForEach-Object commands that operate on each piped object, especially when calling methods.

Key terms: ForEach-Object, script block, $_, pipeline, properties, methods, %, ForEach, method, parameters

15.6 Lab

15.7 Lab answers

Where this is used later

Concepts explained in this chapter

← Chapter 14: Multitasking with background jobs Chapter 16: Variables: A place to store your stuff →

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.