liveBook · Manning

-scriptblock

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

-ScriptBlock is an Invoke-Command parameter that specifies executable PowerShell statements to run remotely.

-ScriptBlock is an Invoke-Command parameter that places executable PowerShell statements inside curly braces for remote computers. The same command can run across multiple hosts, while a separate parameter can send an entire script file instead. section 13.6

Run a process query remotely

Invoke-Command -ComputerName SRV2,DC3,SRV4 -ScriptBlock { Get-Process pwsh } -UserName tylerl The statements inside the braces are sent to each specified computer. A pipeline can be included inside the block to filter the remote results. section 13.6

Invoke-Command -ComputerName SRV2,DC3,SRV4
-ScriptBlock { Get-Process pwsh } -UserName tylerl

Compare the parameter with -HostName and observe how the script block is combined with a computer list. section 13.6

With -AsJob, -ScriptBlock sends the command to remote computers in parallel and stores returned results until they are reviewed. The remote-job approach supports up to 32 simultaneous computers by default. section 14.5

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

How deep it goes
Explains placement, multi-host execution, script-file alternatives, and parallel jobs without detailing script-block internals.
Examples
Demonstrates Get-Process, Where-Object filtering, host-name files, and remote jobs.
What it assumes
Assumes basic Invoke-Command and remoting knowledge while reinforcing parameter help and curly-brace command grouping.
What you can do after
Apply it via Invoke-Command to distribute commands, filters, or longer-running work across remote computers.
How it connects
Connects remote execution with Invoke-Command, PowerShell remoting, script files, background jobs, and SSH.

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.