1
00:00:00,430 --> 00:00:02,070
Okay, so let's go and have a look at how

2
00:00:02,070 --> 00:00:07,340
we remove remote background jobs. Okay, so

3
00:00:07,340 --> 00:00:08,690
what we looked at last time was the

4
00:00:08,690 --> 00:00:11,020
creation of the jobs, but what about if we

5
00:00:11,020 --> 00:00:15,240
wanted to remove a specific job? Well,

6
00:00:15,240 --> 00:00:17,630
first off, we know that Get‑Job is going

7
00:00:17,630 --> 00:00:20,610
to retrieve any jobs, and we also know

8
00:00:20,610 --> 00:00:24,050
that if I say Remove‑Job, and pass in the

9
00:00:24,050 --> 00:00:27,110
Id, that that will clear those jobs down.

10
00:00:27,110 --> 00:00:30,640
And that's a local job. But what about a

11
00:00:30,640 --> 00:00:33,460
remote job? So let me go back into my

12
00:00:33,460 --> 00:00:35,190
session, and you can see I still have my

13
00:00:35,190 --> 00:00:40,380
existing session created. So how do I get

14
00:00:40,380 --> 00:00:45,370
those jobs from that remote machine? So

15
00:00:45,370 --> 00:00:48,890
what we can do here is I could say. let me

16
00:00:48,890 --> 00:00:52,180
just clear this, I could say $job, which

17
00:00:52,180 --> 00:00:53,400
is going to be the job that I want to get

18
00:00:53,400 --> 00:01:00,720
back. I could say Invoke‑Command, and I'm

19
00:01:00,720 --> 00:01:04,220
going to pass it into the session, so this

20
00:01:04,220 --> 00:01:07,030
session to the remote machine, and then

21
00:01:07,030 --> 00:01:09,750
I'm going to say ScriptBlock. And then of

22
00:01:09,750 --> 00:01:12,320
course we pass in some various options,

23
00:01:12,320 --> 00:01:15,460
and I'm going to say Get‑Job. So let's

24
00:01:15,460 --> 00:01:18,140
just execute that. Now what does that look

25
00:01:18,140 --> 00:01:20,560
like? Well, there we go. It brings back

26
00:01:20,560 --> 00:01:24,040
the job from the remote machine. So I

27
00:01:24,040 --> 00:01:27,110
basically invoke a command to use Get‑Job.

28
00:01:27,110 --> 00:01:29,480
So how do I remove that job because now

29
00:01:29,480 --> 00:01:32,260
I've got that one. What I can actually do

30
00:01:32,260 --> 00:01:39,200
is I can say $job, and if I say Get‑Job,

31
00:01:39,200 --> 00:01:40,970
and notice what happens, it says the

32
00:01:40,970 --> 00:01:43,470
command cannot find a job with the job ID

33
00:01:43,470 --> 00:01:46,160
1. That's because remember, where does job

34
00:01:46,160 --> 00:01:49,120
1 exist, not locally, and the standard

35
00:01:49,120 --> 00:01:52,400
Get‑Job command is tied to this local

36
00:01:52,400 --> 00:01:55,900
machine here. So how do we get rid of that

37
00:01:55,900 --> 00:01:59,000
specific one? Well, let's try doing job,

38
00:01:59,000 --> 00:02:02,180
and we'll do that. And then we'll say

39
00:02:02,180 --> 00:02:05,210
Remove‑Job, and we'll do that. Oh, wait,

40
00:02:05,210 --> 00:02:08,770
same issue. It comes back as a failure. So

41
00:02:08,770 --> 00:02:11,520
how do we clear the jobs down? Well, let's

42
00:02:11,520 --> 00:02:14,250
think about this. It's going to be where

43
00:02:14,250 --> 00:02:20,520
we can actually say Invoke‑Command, push

44
00:02:20,520 --> 00:02:23,200
it into the existing session on the remote

45
00:02:23,200 --> 00:02:27,510
one, say ScriptBlock, and then I'm going

46
00:02:27,510 --> 00:02:32,950
to say Remove‑Job ‑Id 1 because I already

47
00:02:32,950 --> 00:02:35,670
know that. Okay, so I initiated a

48
00:02:35,670 --> 00:02:39,840
connection, and I told it to remove. Now I

49
00:02:39,840 --> 00:02:42,310
have a connection here. So how do we get

50
00:02:42,310 --> 00:02:45,130
the jobs back for that? Well think of what

51
00:02:45,130 --> 00:02:47,460
we just did, we just did remove. We know

52
00:02:47,460 --> 00:02:51,810
that the Get‑Job command will return jobs,

53
00:02:51,810 --> 00:02:53,800
and sure enough, it's been deleted. So we

54
00:02:53,800 --> 00:02:56,790
can remove jobs utilizing the same

55
00:02:56,790 --> 00:02:59,450
mechanism that we did for creating of jobs

56
00:02:59,450 --> 00:03:02,140
and getting jobs from the remote machines.

57
00:03:02,140 --> 00:03:05,110
So when we execute the job on, you know,

58
00:03:05,110 --> 00:03:08,610
multiple computers, to retrieve or remove

59
00:03:08,610 --> 00:03:11,290
that, we need to go back into the existing

60
00:03:11,290 --> 00:03:16,000
session, so that we can then execute the commands using an invoke command.

