1
00:00:00,620 --> 00:00:02,830
So let's go ahead and let's create some

2
00:00:02,830 --> 00:00:06,140
background jobs utilizing each of those

3
00:00:06,140 --> 00:00:12,340
approaches. Okay, so we're back on the

4
00:00:12,340 --> 00:00:14,970
PowerShell client. Now in order for us to

5
00:00:14,970 --> 00:00:18,030
create a job, there's obviously a couple

6
00:00:18,030 --> 00:00:20,040
different ways of doing this. So the first

7
00:00:20,040 --> 00:00:23,550
one we did look at was Start‑Job. And this

8
00:00:23,550 --> 00:00:25,300
one, obviously, we can pass a ScriptBlock.

9
00:00:25,300 --> 00:00:27,430
We use our squirrely brackets is before.

10
00:00:27,430 --> 00:00:30,390
So I'm going to stick to use in the

11
00:00:30,390 --> 00:00:35,200
Get‑Process one. And we'll pass a name,

12
00:00:35,200 --> 00:00:40,640
and we'll look for Notepad. Okay, so our

13
00:00:40,640 --> 00:00:42,150
job is now created. Fairly

14
00:00:42,150 --> 00:00:44,960
straightforward. Just the standard way of

15
00:00:44,960 --> 00:00:47,880
creating a job. Now let's say we just

16
00:00:47,880 --> 00:00:51,110
wanted to get that process, let's say by

17
00:00:51,110 --> 00:00:54,000
name, and we'll use Notepad again, and I

18
00:00:54,000 --> 00:00:56,460
wanted to create it as a job. Well now I

19
00:00:56,460 --> 00:00:58,400
can just pass in the ampersand prompt

20
00:00:58,400 --> 00:01:00,520
parameter at the end, and you'll see it

21
00:01:00,520 --> 00:01:03,580
now creates a job automatically. So if I

22
00:01:03,580 --> 00:01:06,990
now choose Get‑Job, you'll see those two

23
00:01:06,990 --> 00:01:10,630
jobs exist. Both were created, one with

24
00:01:10,630 --> 00:01:14,440
Start‑Job and then one with the operator

25
00:01:14,440 --> 00:01:16,860
using the ampersand character. Now the

26
00:01:16,860 --> 00:01:19,130
third option is I'm going to create a

27
00:01:19,130 --> 00:01:23,530
variable called job, and I'm going to use

28
00:01:23,530 --> 00:01:26,790
Invoke‑Command. And then from here, I'm

29
00:01:26,790 --> 00:01:29,600
just going to say ScriptBlock, and we'll

30
00:01:29,600 --> 00:01:31,870
use our squirrely brackets as before. I'm

31
00:01:31,870 --> 00:01:36,490
going to say Get‑Process. Exactly the same

32
00:01:36,490 --> 00:01:42,460
as we did before. Notepad. Then I'm going

33
00:01:42,460 --> 00:01:46,210
to go and say JobName, and we'll call this

34
00:01:46,210 --> 00:01:49,020
one Notepad so we can differentiate it.

35
00:01:49,020 --> 00:01:51,660
And then I'm going to use this AsJob

36
00:01:51,660 --> 00:01:53,920
parameter. So that's going to be

37
00:01:53,920 --> 00:01:56,350
Invoke‑Command ScriptBlock, give it a

38
00:01:56,350 --> 00:01:59,920
name, and then do AsJob. Now what does it

39
00:01:59,920 --> 00:02:01,510
say when it comes up? It says parameter

40
00:02:01,510 --> 00:02:04,120
set cannot be resolved using the specified

41
00:02:04,120 --> 00:02:06,670
name parameters. One or more parameters

42
00:02:06,670 --> 00:02:09,180
issued cannot be used together or there's

43
00:02:09,180 --> 00:02:13,410
an insufficient number of parameters. So

44
00:02:13,410 --> 00:02:14,760
what does that mean? Well, it tells me

45
00:02:14,760 --> 00:02:16,910
that there's a parameter that's missing.

46
00:02:16,910 --> 00:02:18,530
So in actual fact, if we go to

47
00:02:18,530 --> 00:02:20,690
Invoke‑Command, what we can actually do

48
00:02:20,690 --> 00:02:24,850
here is if we just drop into this one, you

49
00:02:24,850 --> 00:02:26,940
can see that there's a ComputerName option

50
00:02:26,940 --> 00:02:29,380
that's available. Now my ComputerName is

51
00:02:29,380 --> 00:02:30,860
called OFFICE, so I'm going to press

52
00:02:30,860 --> 00:02:33,020
Enter. And notice this time it did

53
00:02:33,020 --> 00:02:36,900
something. It didn't error. It just did

54
00:02:36,900 --> 00:02:39,090
something. So what does that look like?

55
00:02:39,090 --> 00:02:42,000
Well, if I just type job and enter, you'll

56
00:02:42,000 --> 00:02:44,690
see that it created a new type of job. Now

57
00:02:44,690 --> 00:02:47,370
just wait, it says RemoteJob versus a

58
00:02:47,370 --> 00:02:50,170
regular job because I passed in a computer

59
00:02:50,170 --> 00:02:52,420
name. Now albeit the same name as the

60
00:02:52,420 --> 00:02:55,770
computer that I'm on, but that created a

61
00:02:55,770 --> 00:02:58,720
RemoteJob. Now if we go back to my syntax

62
00:02:58,720 --> 00:03:01,940
and let's just do Get‑Name one that's

63
00:03:01,940 --> 00:03:04,150
there, you can see that the first one that

64
00:03:04,150 --> 00:03:07,100
I created is the background job, and the

65
00:03:07,100 --> 00:03:09,780
second one is a remote job. So just be

66
00:03:09,780 --> 00:03:11,880
aware depending on how you decide to

67
00:03:11,880 --> 00:03:14,950
create the job or dictate the type of job

68
00:03:14,950 --> 00:03:17,700
that gets create. Now when we actually

69
00:03:17,700 --> 00:03:20,060
create jobs, we can obviously start to be

70
00:03:20,060 --> 00:03:25,350
very creative. So if I do Start‑Job, I can

71
00:03:25,350 --> 00:03:31,370
do ScriptBlock, and then maybe I want to

72
00:03:31,370 --> 00:03:36,610
start a job in here as well if I wanted to

73
00:03:36,610 --> 00:03:39,370
because that's also a command. Or I could

74
00:03:39,370 --> 00:03:46,420
say, let's do Get‑Process and Notepad. And

75
00:03:46,420 --> 00:03:49,150
then, of course, I can then start to

76
00:03:49,150 --> 00:03:52,110
expand that script process. Maybe I do

77
00:03:52,110 --> 00:03:56,440
want to go ahead and say Start‑Job

78
00:03:56,440 --> 00:04:02,820
ScriptBlock and then start to nest

79
00:04:02,820 --> 00:04:05,870
specific commands. Now these are not the

80
00:04:05,870 --> 00:04:07,550
easiest to do because you're obviously

81
00:04:07,550 --> 00:04:10,000
starting to nest commands inside of each

82
00:04:10,000 --> 00:04:12,540
other. But you do have the flexibility of

83
00:04:12,540 --> 00:04:15,090
saying well, I have this process, then I

84
00:04:15,090 --> 00:04:17,380
have this process, then I have another

85
00:04:17,380 --> 00:04:19,620
process that I would like to kind of

86
00:04:19,620 --> 00:04:23,000
inject into that same. Now if I try to

87
00:04:23,000 --> 00:04:24,950
execute this, I want you to see what

88
00:04:24,950 --> 00:04:27,560
happens. Okay, so it created a background

89
00:04:27,560 --> 00:04:30,640
job. But what job did it create? Well,

90
00:04:30,640 --> 00:04:33,030
there was a job and then I told it to

91
00:04:33,030 --> 00:04:35,980
create a job. And then I told it to get a

92
00:04:35,980 --> 00:04:38,470
process. So this is where we can actually

93
00:04:38,470 --> 00:04:41,430
use the Get‑Job option, and I can say

94
00:04:41,430 --> 00:04:43,910
include children. And what you'll see is

95
00:04:43,910 --> 00:04:46,440
it goes and gets me all the list of jobs,

96
00:04:46,440 --> 00:04:48,930
and you can see that it lists me out all

97
00:04:48,930 --> 00:04:51,320
of the jobs that got created. So you can

98
00:04:51,320 --> 00:04:54,080
see I've got my Job35 at the bottom, which

99
00:04:54,080 --> 00:04:56,010
is my background job. And then I've got my

100
00:04:56,010 --> 00:04:58,660
child job, which is Job36, which is the

101
00:04:58,660 --> 00:05:01,000
one that was created. So we can see that

102
00:05:01,000 --> 00:05:05,120
we can start to name and at least condense

103
00:05:05,120 --> 00:05:07,180
all of those jobs into one kind of

104
00:05:07,180 --> 00:05:10,410
command. So let me just clear that. So it

105
00:05:10,410 --> 00:05:11,740
is a little bit more complicated, I will

106
00:05:11,740 --> 00:05:13,440
be honest with you, to try and nest them

107
00:05:13,440 --> 00:05:15,490
all together. Where possible, you probably

108
00:05:15,490 --> 00:05:18,550
just want to utilize a standard, either

109
00:05:18,550 --> 00:05:24,000
Start‑Job or maybe an Invoke command and then nest the jobs as needed there.

