Script block
A script block is a PowerShell construct that groups executable statements within braces for storage, invocation, or deferred execution as a unit.
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.
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.
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.
Related concepts
- -scriptblockused by · -ScriptBlock is an Invoke-Command parameter that specifies executable PowerShell statements to run remotely.
- loopused by · A loop is a programming control-flow construct that repeatedly executes a block of instructions according to an iteration rule or continuation condition.
- ValidateScript attributeused by · The ValidateScript attribute validates a PowerShell parameter by evaluating a script block against its supplied value.
- placeholderuses · A placeholder is a temporary or symbolic stand-in for a value, content, component, or position that is supplied, replaced, or resolved later.
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.


