1
00:00:00,940 --> 00:00:03,440
Okay, so now that we've created jobs and

2
00:00:03,440 --> 00:00:05,330
we can remove them, we now need to

3
00:00:05,330 --> 00:00:07,170
understand how we can wait for background

4
00:00:07,170 --> 00:00:09,170
jobs to actually complete. And, of course,

5
00:00:09,170 --> 00:00:11,180
that would be useful to know, because we

6
00:00:11,180 --> 00:00:13,050
need to know that the jobs have completed

7
00:00:13,050 --> 00:00:14,810
so that we can execute other things

8
00:00:14,810 --> 00:00:17,530
afterwards. So the command we'll use is

9
00:00:17,530 --> 00:00:20,980
Wait‑Job. What this one does is suppresses

10
00:00:20,980 --> 00:00:23,850
the command prompt until one or all of the

11
00:00:23,850 --> 00:00:25,520
PowerShell background jobs running in the

12
00:00:25,520 --> 00:00:27,770
session are complete. That's what it's

13
00:00:27,770 --> 00:00:31,760
designed for. If I want to utilize Wait, I

14
00:00:31,760 --> 00:00:35,670
can say Get‑Job | Wait‑Job. And that will

15
00:00:35,670 --> 00:00:38,160
actually tell me to wait for that specific

16
00:00:38,160 --> 00:00:40,380
job to complete and suppress the command

17
00:00:40,380 --> 00:00:43,460
prompt. I could then wait for several jobs

18
00:00:43,460 --> 00:00:47,210
by ID to finish. So I could say Wait‑Job,

19
00:00:47,210 --> 00:00:49,980
specific ones that are executing by ID,

20
00:00:49,980 --> 00:00:53,240
and then it will suppress again and wait.

21
00:00:53,240 --> 00:00:55,140
I could also then wait for any of the

22
00:00:55,140 --> 00:00:57,660
Invoke‑Command options to run. So if I'm

23
00:00:57,660 --> 00:01:00,670
doing Invoke‑Command into a new PowerShell

24
00:01:00,670 --> 00:01:02,700
session, as we did previously with the

25
00:01:02,700 --> 00:01:05,580
Get‑Process ‑AsJob, I could then say get

26
00:01:05,580 --> 00:01:08,220
that job and then just wait. So we have a

27
00:01:08,220 --> 00:01:11,840
way of kind of waiting or at least forcing

28
00:01:11,840 --> 00:01:15,120
the console to wait for a job to complete.

29
00:01:15,120 --> 00:01:20,000
This is helpful if you're trying to review what's going on in that job itself.

