Welcome back everyone. Up next, we're going to look at PowerShell script blocks.
These are language elements that are used all the time in
PowerShell. I know you've seen them,
I know I've used them, but let me go through and explain in a
little more detail about what these things are.
A script block, by way of definition, is a collection of statements or
expressions, and by that I mean PowerShell code, in essence,
that can be used as a single unit.
A script block can use parameters, and it writes to the pipeline.
Here are some details.
A script block, again, as I said, is a core PowerShell language element.
It's used, for example, in things such as Where‑Object,
ForEach‑Object, Invoke‑Command, and a lot of other Ad‑hoc
commands that you might want to throw together.
It's a way of defining a block of commands or a group of
commands that you want to execute, but it allows you to do it
from a very granular level, because you can basically save them
all in one little script block,
which you save to a variable, and then you just run that, so it
saves you a lot of typing. In the documentation, you'll see these
things referred to as scriptblocks, all one word, or script blocks, two words.
Complex script blocks are often used in PowerShell scripting, and again,
that's not something we're going to cover in this course, but once you
understand what a script block looks like and how it functions, once you do get to scripting, you'll be ready to go.