1
00:00:00,280 --> 00:00:03,600
So let's go back onto the machine, and

2
00:00:03,600 --> 00:00:05,570
we'll look at how we wait for remote

3
00:00:05,570 --> 00:00:09,170
background jobs to complete. Okay, so one

4
00:00:09,170 --> 00:00:10,490
of the last things that we want to focus

5
00:00:10,490 --> 00:00:12,200
on is, what about if you're trying to

6
00:00:12,200 --> 00:00:16,070
execute a fairly large job on multiple

7
00:00:16,070 --> 00:00:19,320
machines and you want to kind of wait for

8
00:00:19,320 --> 00:00:21,460
those to kind of be completed? Well, we

9
00:00:21,460 --> 00:00:23,220
talked about this previously about waiting

10
00:00:23,220 --> 00:00:25,880
for jobs using the Wait‑Job command, and

11
00:00:25,880 --> 00:00:28,540
kind of what does the Wait‑Job do? It

12
00:00:28,540 --> 00:00:32,210
stops the user interface from kind of, it

13
00:00:32,210 --> 00:00:34,180
kind of locks it up, so you can't actually

14
00:00:34,180 --> 00:00:36,040
do anything else. We also talked about,

15
00:00:36,040 --> 00:00:37,760
for example, using things like if we're

16
00:00:37,760 --> 00:00:39,770
debugging different things as ways to kind

17
00:00:39,770 --> 00:00:43,600
of intercept that. So let's have a look at

18
00:00:43,600 --> 00:00:45,420
how this works. So, first off, what I want

19
00:00:45,420 --> 00:00:47,900
to do is just look at, and make sure our

20
00:00:47,900 --> 00:00:49,830
PS session is still live, which it is.

21
00:00:49,830 --> 00:00:54,590
Okay, so I have my session. So let me

22
00:00:54,590 --> 00:00:59,260
invoke a command, and we're going to drop

23
00:00:59,260 --> 00:01:02,890
that into the same session, and in my

24
00:01:02,890 --> 00:01:07,070
script block, I'm going to start a new

25
00:01:07,070 --> 00:01:09,800
job. So start a new job. I'm going to give

26
00:01:09,800 --> 00:01:12,140
it a name this time, and we'll just call

27
00:01:12,140 --> 00:01:14,040
this Job1, because I want a reference it

28
00:01:14,040 --> 00:01:18,270
by name. And then once we have that kind

29
00:01:18,270 --> 00:01:20,710
of job set up, I want to put a script

30
00:01:20,710 --> 00:01:23,130
block into that, and we'll just use this

31
00:01:23,130 --> 00:01:24,760
Standard‑Get process. I do that just

32
00:01:24,760 --> 00:01:26,430
because I know it's going to take some

33
00:01:26,430 --> 00:01:29,080
time to execute. Okay, so this is going to

34
00:01:29,080 --> 00:01:34,490
go ahead on and invoke a specific job

35
00:01:34,490 --> 00:01:37,000
that's being started on the remote

36
00:01:37,000 --> 00:01:40,130
machine. So let's just execute there. I'm

37
00:01:40,130 --> 00:01:44,000
now going to create a new variable and

38
00:01:44,000 --> 00:01:49,690
initiate a new command ‑Session Session,

39
00:01:49,690 --> 00:01:53,800
and my command is actually going to be

40
00:01:53,800 --> 00:02:02,260
Wait‑Job ‑name and Job1, and Enter there.

41
00:02:02,260 --> 00:02:04,270
And let's have a look here. Now, of

42
00:02:04,270 --> 00:02:06,570
course, timing is everything here. So what

43
00:02:06,570 --> 00:02:09,810
we ended up with is the job ran, and then,

44
00:02:09,810 --> 00:02:12,210
of course, I then went through the invoke

45
00:02:12,210 --> 00:02:14,460
one to wait for the job to actually

46
00:02:14,460 --> 00:02:17,030
execute, but of course, it had completed

47
00:02:17,030 --> 00:02:19,160
in between then. So what we can do is if

48
00:02:19,160 --> 00:02:21,930
we do the same thing, I can then do that

49
00:02:21,930 --> 00:02:23,620
one, and you'll see it now locks the

50
00:02:23,620 --> 00:02:26,030
interface for the remote job that's

51
00:02:26,030 --> 00:02:28,250
running on the other machine. When that

52
00:02:28,250 --> 00:02:30,880
job completes, it will then come back and

53
00:02:30,880 --> 00:02:34,230
release the interface to me while that,

54
00:02:34,230 --> 00:02:36,800
after that remote job is now finished. So

55
00:02:36,800 --> 00:02:38,350
the same principle that we use for doing

56
00:02:38,350 --> 00:02:40,950
local jobs that when we have a local job

57
00:02:40,950 --> 00:02:42,920
that runs, obviously, depending on the

58
00:02:42,920 --> 00:02:44,440
size of the job and the scripts that we're

59
00:02:44,440 --> 00:02:45,600
running, there we go; it's never been

60
00:02:45,600 --> 00:02:48,150
released. I can do the same thing for a

61
00:02:48,150 --> 00:02:50,610
remote background job as well. So fairly

62
00:02:50,610 --> 00:02:52,100
straightforward to understand there. It's

63
00:02:52,100 --> 00:02:54,290
still the same syntax as a local one,

64
00:02:54,290 --> 00:02:55,930
except we can start to nest things

65
00:02:55,930 --> 00:02:58,220
together, and run something against a

66
00:02:58,220 --> 00:03:00,730
machine, and then know for sure that it's

67
00:03:00,730 --> 00:03:05,000
been completed, because it releases the user interface at that point.

