liveBook · Manning

Batch cmdlet

As explained in Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS

A batch cmdlet is a PowerShell cmdlet technique for applying an operation to multiple targets in a single command invocation.

A batch cmdlet applies one operation to a collection of objects in a single PowerShell command. Pipe multiple targets to a cmdlet designed to accept them, rather than handling each target separately. section 15.0 section 15.1

For example, Get-Service BITS,Spooler | Set-Service -StartupType Automatic changes both services. Action cmdlets may produce no visible output; add -PassThru when you want the modified objects displayed for verification. section 15.1

Copy several items and inspect the result

Get-ChildItem .\ | Copy-Item -Destination C:\Drivers -PassThru copies the current directory’s items and displays what Copy-Item accepted. Without -PassThru, the command normally returns to the prompt without showing results. section 15.1

Get-Service BITS,Spooler | Set-Service -startuptype Automatic

Compare a compact multi-service command with other supplied batch-cmdlet examples. section 15.1

How Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS covers it

How deep it goes
Explains collection input, pipeline use, verification with PassThru, and alternatives without detailing cmdlet internals.
Examples
Demonstrates stopping services, changing service startup types, copying directory items, and stopping matching processes.
What it assumes
Assumes familiarity with PowerShell objects and piping cmdlet output into another cmdlet.
What you can do after
Apply it via PowerShell pipelines to perform repeatable actions on groups of administrative objects.
How it connects
Connects PowerShell pipelines with object enumeration, ForEach-Object, and action cmdlets.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS. The section links point to the parts of the book it draws on.