1
00:00:00,820 --> 00:00:03,480
So let's go into our PowerShell, and we'll

2
00:00:03,480 --> 00:00:05,800
look at reviewing PowerShell background

3
00:00:05,800 --> 00:00:07,970
job commands and how to create some of

4
00:00:07,970 --> 00:00:16,160
those jobs. Okay, so we're on our

5
00:00:16,160 --> 00:00:19,520
PowerShell 7 console. Actually, this is

6
00:00:19,520 --> 00:00:22,650
the Windows 10 terminal console. So first

7
00:00:22,650 --> 00:00:24,850
off, what I want to do is actually just

8
00:00:24,850 --> 00:00:26,480
look at some of the variables that are

9
00:00:26,480 --> 00:00:29,570
available. If I click $PSVersionTable, you

10
00:00:29,570 --> 00:00:31,210
can see it will give me the current

11
00:00:31,210 --> 00:00:33,340
version, so you can see I'm using 7.0.3,

12
00:00:33,340 --> 00:00:36,000
the Core edition, and it tells me I'm

13
00:00:36,000 --> 00:00:39,410
using Windows 10, etc. If I just want to

14
00:00:39,410 --> 00:00:41,670
look at a specific property, I can say

15
00:00:41,670 --> 00:00:43,900
$PSVersion, and it will give me the Major,

16
00:00:43,900 --> 00:00:47,100
Minor, Patch, etc. Now, of course, what we

17
00:00:47,100 --> 00:00:49,040
want to do here is look at how we create

18
00:00:49,040 --> 00:00:52,480
those jobs. So our first syntax here is

19
00:00:52,480 --> 00:00:56,060
Start‑Job. But, actually, what other job

20
00:00:56,060 --> 00:00:58,410
commands are available? We can say

21
00:00:58,410 --> 00:01:01,540
Get‑Command. And then what I'm going to do

22
00:01:01,540 --> 00:01:06,230
is just do *job* and there. And you'll see

23
00:01:06,230 --> 00:01:08,400
that when I look in the list, if I scroll

24
00:01:08,400 --> 00:01:10,040
back up, you can see PrintJob, StorageJob,

25
00:01:10,040 --> 00:01:13,380
PrintJob, Debug‑Job, Get‑Job, JobTrigger,

26
00:01:13,380 --> 00:01:15,630
Remove. So there's a whole host of

27
00:01:15,630 --> 00:01:18,530
different types of jobs that are

28
00:01:18,530 --> 00:01:20,470
available. So tell you what, let's just

29
00:01:20,470 --> 00:01:22,760
clear that screen again. And this time

30
00:01:22,760 --> 00:01:25,750
I'll get rid of the star and just do job.

31
00:01:25,750 --> 00:01:27,800
Now, of course, that doesn't work because

32
00:01:27,800 --> 00:01:29,110
it can't find something that's

33
00:01:29,110 --> 00:01:32,790
specifically just job. So if I do star,

34
00:01:32,790 --> 00:01:34,210
then, of course, you'll see some of those

35
00:01:34,210 --> 00:01:36,090
job ones disappear, and some of them

36
00:01:36,090 --> 00:01:38,490
don't. But either way, you can kind of see

37
00:01:38,490 --> 00:01:40,610
the version of the PowerShell that it's

38
00:01:40,610 --> 00:01:42,680
part of. But the most important ones will

39
00:01:42,680 --> 00:01:45,080
be Wait‑Job, Stop‑Jobs, Start‑Job,

40
00:01:45,080 --> 00:01:48,940
Remove‑Job, Receive, Get‑Job, etc. Now

41
00:01:48,940 --> 00:01:50,890
these commands themselves, if I click

42
00:01:50,890 --> 00:01:55,150
Start‑Job here and just do Enter, the

43
00:01:55,150 --> 00:01:57,200
default property will be the ScriptBlock

44
00:01:57,200 --> 00:01:59,460
itself, which is going to ask me for

45
00:01:59,460 --> 00:02:03,290
something to happen. Now if I look at what

46
00:02:03,290 --> 00:02:04,860
would be a standard one, it would be

47
00:02:04,860 --> 00:02:06,970
Get‑Process. And, of course, notice what

48
00:02:06,970 --> 00:02:09,140
happens. It says, Well, I can't take that

49
00:02:09,140 --> 00:02:11,520
value because I don't quite know what

50
00:02:11,520 --> 00:02:15,160
that's doing. If I type Get‑Process, for

51
00:02:15,160 --> 00:02:17,300
example, here, that's going to execute

52
00:02:17,300 --> 00:02:19,610
anyway. So why does it not work in the

53
00:02:19,610 --> 00:02:22,510
Start‑Job? And that's because if we look

54
00:02:22,510 --> 00:02:25,080
at the Start‑Job syntax here and just do

55
00:02:25,080 --> 00:02:27,620
‑ScriptBlock, a ScriptBlock needs to be

56
00:02:27,620 --> 00:02:30,310
encompassed inside the squirrelly brackets

57
00:02:30,310 --> 00:02:32,640
here. So at this point, I can say

58
00:02:32,640 --> 00:02:35,630
Get‑Process and execute, and the job then

59
00:02:35,630 --> 00:02:37,960
works. So just be aware that you can't

60
00:02:37,960 --> 00:02:39,970
just paste whatever you want to into that

61
00:02:39,970 --> 00:02:43,270
ScriptBlock. Now let's say I want to look

62
00:02:43,270 --> 00:02:44,710
at the other property, so I've got the

63
00:02:44,710 --> 00:02:48,440
‑Name, so I can put a name here, so

64
00:02:48,440 --> 00:02:50,530
TestJob. Then if we go a bit further,

65
00:02:50,530 --> 00:02:52,170
we've got Credentials. I've got

66
00:02:52,170 --> 00:02:53,570
Authentication. I've got

67
00:02:53,570 --> 00:02:54,980
InitializationScript, the

68
00:02:54,980 --> 00:02:58,620
WorkingDirectory, 32‑bit runners, etc.,

69
00:02:58,620 --> 00:03:01,080
and I can keep going. If I want to choose

70
00:03:01,080 --> 00:03:03,960
Verbose, for example, I can do Verbose.

71
00:03:03,960 --> 00:03:05,440
Now there's nothing that comes back

72
00:03:05,440 --> 00:03:07,200
because, literally, when you kick off a

73
00:03:07,200 --> 00:03:09,290
job, that's where it ends up. So it's

74
00:03:09,290 --> 00:03:11,470
fairly straightforward. Now if I choose

75
00:03:11,470 --> 00:03:13,570
Get‑Job, which is another command, this'll

76
00:03:13,570 --> 00:03:15,630
list me the jobs that are there, and you

77
00:03:15,630 --> 00:03:18,450
can see that my TestJob there is actually

78
00:03:18,450 --> 00:03:20,520
in the middle of executing. So let me just

79
00:03:20,520 --> 00:03:24,140
clear that one. If I choose Get‑Job again,

80
00:03:24,140 --> 00:03:27,770
you'll see I can change this and say ‑Id,

81
00:03:27,770 --> 00:03:31,000
and I'll choose 23. So this will now

82
00:03:31,000 --> 00:03:34,950
return back and say Job 23, and it's been

83
00:03:34,950 --> 00:03:38,790
completed. I could also then choose other

84
00:03:38,790 --> 00:03:41,210
properties such as ‑IncludeChildJob, and

85
00:03:41,210 --> 00:03:43,150
you'll see this is an introduction here,

86
00:03:43,150 --> 00:03:45,180
this piece. You'll see that the parent is

87
00:03:45,180 --> 00:03:47,650
a job, and then the actual job or the

88
00:03:47,650 --> 00:03:51,320
command that executes is a child job. We

89
00:03:51,320 --> 00:03:55,530
also have the ability to remove a job

90
00:03:55,530 --> 00:03:59,240
also. That is also done by the ID or the

91
00:03:59,240 --> 00:04:02,220
instance of the ID. Now, if we go back to

92
00:04:02,220 --> 00:04:04,950
Get‑Job, you can see I've got my numbers

93
00:04:04,950 --> 00:04:07,970
here. I can say Get‑Job, and then I can

94
00:04:07,970 --> 00:04:13,190
say, I don't want Remove‑Aip, Remove‑Job,

95
00:04:13,190 --> 00:04:16,180
and Enter. If I now choose Get‑Job,

96
00:04:16,180 --> 00:04:18,770
there'll be no jobs available. So the

97
00:04:18,770 --> 00:04:20,860
basic commands are really simple. You

98
00:04:20,860 --> 00:04:22,640
obviously need to understand which pieces

99
00:04:22,640 --> 00:04:25,420
to pass into it, such as the properties,

100
00:04:25,420 --> 00:04:28,110
the various variables. For example, if we

101
00:04:28,110 --> 00:04:31,100
go back to our Start‑Job command and then

102
00:04:31,100 --> 00:04:33,540
do a ‑ScriptBlock, we have our squirrelly

103
00:04:33,540 --> 00:04:35,670
brackets here, and then I'm going to

104
00:04:35,670 --> 00:04:39,620
choose Get‑Process. In here I have

105
00:04:39,620 --> 00:04:42,700
whatever the properties are for the

106
00:04:42,700 --> 00:04:45,060
Get‑Process. So just be aware that as we

107
00:04:45,060 --> 00:04:47,130
join things together, we can get quite

108
00:04:47,130 --> 00:04:49,340
nested in the types of commands that we

109
00:04:49,340 --> 00:04:52,030
can pass. So if I just choose, Get‑Process

110
00:04:52,030 --> 00:04:56,350
‑Name pwsh for PowerShell, I can start the

111
00:04:56,350 --> 00:05:00,550
job, and then when it's finished, if I

112
00:05:00,550 --> 00:05:01,840
just go back here, and we can choose

113
00:05:01,840 --> 00:05:06,330
Get‑Job, Get‑Job, it'll say it's completed

114
00:05:06,330 --> 00:05:10,040
now. And so I have that job executed. Now

115
00:05:10,040 --> 00:05:11,890
what does that mean though? Well, the job

116
00:05:11,890 --> 00:05:14,440
executed, and I have no information that's

117
00:05:14,440 --> 00:05:22,160
come back. So I can say Receive, I got the

118
00:05:22,160 --> 00:05:25,510
e and the i in the wrong way, Receive‑Job,

119
00:05:25,510 --> 00:05:33,340
and I can pick a job ID and say 25, and,

120
00:05:33,340 --> 00:05:35,360
sure enough, it comes back and says, Yep,

121
00:05:35,360 --> 00:05:37,190
there are your processes. So notice that

122
00:05:37,190 --> 00:05:39,340
the tie there where we have the job that

123
00:05:39,340 --> 00:05:41,220
was created, we can retrieve the job

124
00:05:41,220 --> 00:05:43,500
status, we can remove the jobs, and then

125
00:05:43,500 --> 00:05:49,000
we have Receive‑Job, which returns the values that are needed from that job.

