1
00:00:01,340 --> 00:00:05,740
Welcome back everyone. Up next, we're going to look at PowerShell script blocks.

2
00:00:05,740 --> 00:00:09,140
These are language elements that are used all the time in

3
00:00:09,140 --> 00:00:11,350
PowerShell. I know you've seen them,

4
00:00:11,350 --> 00:00:14,390
I know I've used them, but let me go through and explain in a

5
00:00:14,390 --> 00:00:17,440
little more detail about what these things are.

6
00:00:17,440 --> 00:00:22,160
A script block, by way of definition, is a collection of statements or

7
00:00:22,160 --> 00:00:25,520
expressions, and by that I mean PowerShell code, in essence,

8
00:00:25,520 --> 00:00:28,440
that can be used as a single unit.

9
00:00:28,440 --> 00:00:33,440
A script block can use parameters, and it writes to the pipeline.

10
00:00:33,440 --> 00:00:34,940
Here are some details.

11
00:00:34,940 --> 00:00:40,140
A script block, again, as I said, is a core PowerShell language element.

12
00:00:40,140 --> 00:00:43,210
It's used, for example, in things such as Where‑Object,

13
00:00:43,210 --> 00:00:47,630
ForEach‑Object, Invoke‑Command, and a lot of other Ad‑hoc

14
00:00:47,630 --> 00:00:50,940
commands that you might want to throw together.

15
00:00:50,940 --> 00:00:54,090
It's a way of defining a block of commands or a group of

16
00:00:54,090 --> 00:00:58,280
commands that you want to execute, but it allows you to do it

17
00:00:58,280 --> 00:01:01,410
from a very granular level, because you can basically save them

18
00:01:01,410 --> 00:01:03,660
all in one little script block,

19
00:01:03,660 --> 00:01:06,280
which you save to a variable, and then you just run that, so it

20
00:01:06,280 --> 00:01:10,780
saves you a lot of typing. In the documentation, you'll see these

21
00:01:10,780 --> 00:01:16,740
things referred to as scriptblocks, all one word, or script blocks, two words.

22
00:01:16,740 --> 00:01:20,110
Complex script blocks are often used in PowerShell scripting, and again,

23
00:01:20,110 --> 00:01:23,240
that's not something we're going to cover in this course, but once you

24
00:01:23,240 --> 00:01:30,000
understand what a script block looks like and how it functions, once you do get to scripting, you'll be ready to go.

