liveBook · Manning

Script block

A script block is a PowerShell construct that groups executable statements within braces for storage, invocation, or deferred execution as a unit.

How 3 Manning books explain it

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

A script block is a PowerShell language construct that groups executable statements inside braces for invocation or deferred execution.

How it is used
Deploys grouped commands for filtering, per-object processing, calculated properties, remoting, jobs, and deferred invocation.
How deep it goes
Explains braces, $_, invocation, and common command parameters, then extends processing to parallel execution and throttle limits.
Examples
Demonstrates process reporting, CSV-derived user properties, Azure Key Vault creation, array iteration, and parallel timing.
What you can do after
Builds reusable command groups and applies them to pipeline objects through ForEach-Object, $_, and the call operator.

Read how Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS explains script block →

Learn PowerShell Scripting in a Month of Lunches, Second Edition: Write and organize scripts and tools

A script block is a grouped sequence of PowerShell statements enclosed in braces that can be executed as a unit.

How it is used
Uses grouped statements to implement conditional decisions, iteration, case selection, and repeated execution in PowerShell.
How deep it goes
Defines syntax and execution behavior across four constructs, but defers deeper script-block internals.
Examples
Demonstrates conditional branches, service iteration, wildcard switch matching, and repeated loops.
What you can do after
Apply it via PowerShell control-flow constructs to group actions, process collections, select cases, and repeat operations.

Read how Learn PowerShell Scripting in a Month of Lunches, Second Edition: Write and organize scripts and tools explains script block →

Practical Automation with PowerShell: Effective scripting from the console to the cloud

A script block is a PowerShell expression that groups commands and can be passed, stored, or invoked as a unit.

How it is used
Uses deferred PowerShell code to generate files and register per-user Active Setup actions.
How deep it goes
Explains declaration, deferred execution, string conversion, and function passing, but stops short of execution-context internals.
Examples
Demonstrates deferred Git configuration passed to New-ActiveSetup and written into a versioned ProgramData script.
What you can do after
Build reusable deferred automation by storing command groups, passing them to functions, and serializing them into script files.

Read how Practical Automation with PowerShell: Effective scripting from the console to the cloud explains script block →

Related concepts

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.