1
00:00:00,310 --> 00:00:02,200
Okay, so let's have a look at how we wait

2
00:00:02,200 --> 00:00:03,850
for the remote background jobs to

3
00:00:03,850 --> 00:00:06,510
complete. Think about that. We may have

4
00:00:06,510 --> 00:00:08,860
1,000 servers that we wish to execute a

5
00:00:08,860 --> 00:00:11,550
command on and we want to be able to wait

6
00:00:11,550 --> 00:00:13,850
for those to complete. Now, in this

7
00:00:13,850 --> 00:00:15,910
example here, we're still using the same

8
00:00:15,910 --> 00:00:17,530
option where we're creating a new

9
00:00:17,530 --> 00:00:19,740
non‑interactive PowerShell session, but

10
00:00:19,740 --> 00:00:21,830
I'm using three machines, Computer1, 2,

11
00:00:21,830 --> 00:00:24,750
and 3. Then I'm going to invoke a command

12
00:00:24,750 --> 00:00:27,160
into those non‑interactive PowerShell

13
00:00:27,160 --> 00:00:29,160
sessions. And then what I'm going to do at

14
00:00:29,160 --> 00:00:30,960
that point is I'm going to pass a

15
00:00:30,960 --> 00:00:32,810
ScriptBlock and you'll see there is a

16
00:00:32,810 --> 00:00:35,240
nested script block here, so we have a

17
00:00:35,240 --> 00:00:37,880
ScriptBlock to start a job and then a

18
00:00:37,880 --> 00:00:41,480
ScriptBlock for that Start‑Job. So you can

19
00:00:41,480 --> 00:00:43,460
see the kind of nest in the structure.

20
00:00:43,460 --> 00:00:45,280
Then underneath that, I have a done

21
00:00:45,280 --> 00:00:47,950
variable where I'm now saying invoke the

22
00:00:47,950 --> 00:00:51,310
command to the session, go and pass a

23
00:00:51,310 --> 00:00:54,460
command which will be Wait‑Job, and then

24
00:00:54,460 --> 00:00:56,330
retrieve the name of the job that I

25
00:00:56,330 --> 00:00:59,460
created in the first invoke. So if we're

26
00:00:59,460 --> 00:01:02,470
creating them remotely, we can actually

27
00:01:02,470 --> 00:01:05,480
kind of structure and nest the ScriptBlock

28
00:01:05,480 --> 00:01:08,000
options to retrieve the values that we need.

