1
00:00:00,640 --> 00:00:02,250
So let's first talk about creating

2
00:00:02,250 --> 00:00:06,660
background jobs. There were two ways that

3
00:00:06,660 --> 00:00:09,190
we can create background jobs. The first

4
00:00:09,190 --> 00:00:10,850
one is to use the PowerShell command

5
00:00:10,850 --> 00:00:13,560
Start‑Job, which is the most common one

6
00:00:13,560 --> 00:00:15,440
that we've already talked about. And the

7
00:00:15,440 --> 00:00:19,570
second one is to use the & sign at the end

8
00:00:19,570 --> 00:00:22,440
of a command, which will then push it into

9
00:00:22,440 --> 00:00:28,800
a job. The Start‑Job command is defined as

10
00:00:28,800 --> 00:00:30,830
the command to start a PowerShell

11
00:00:30,830 --> 00:00:33,210
background job. It serves no other purpose

12
00:00:33,210 --> 00:00:36,820
apart from starting a job. Now to create a

13
00:00:36,820 --> 00:00:39,250
background job, we can do this by

14
00:00:39,250 --> 00:00:41,660
utilizing Start‑Job. Remember, we talked

15
00:00:41,660 --> 00:00:43,540
about passing the script block, and I'm

16
00:00:43,540 --> 00:00:45,060
going to say go and get the process for

17
00:00:45,060 --> 00:00:47,680
notepad. And this will initiate the

18
00:00:47,680 --> 00:00:50,170
creation of a background job, using the

19
00:00:50,170 --> 00:00:54,080
standard Start‑Job. Now, if we take this

20
00:00:54,080 --> 00:00:58,240
same example and utilize the & property,

21
00:00:58,240 --> 00:01:00,810
then what we end up with is GetProcess

22
00:01:00,810 --> 00:01:05,010
‑Name notepad and then the & operator. So

23
00:01:05,010 --> 00:01:07,320
notice how that changes. The first one we

24
00:01:07,320 --> 00:01:10,520
use Start‑Job, and then we say go and

25
00:01:10,520 --> 00:01:12,480
create it and this is the script block.

26
00:01:12,480 --> 00:01:14,330
The second one, we get rid of the script

27
00:01:14,330 --> 00:01:17,430
block and the start job, and just call the

28
00:01:17,430 --> 00:01:20,310
code that we wish to execute with an & at

29
00:01:20,310 --> 00:01:23,980
the end. A third option here is to utilize

30
00:01:23,980 --> 00:01:27,110
the Invoke‑Command and use the ‑AsJob

31
00:01:27,110 --> 00:01:29,250
parameter. So in this instance, I'm going

32
00:01:29,250 --> 00:01:32,020
to say go and invoke a command on a

33
00:01:32,020 --> 00:01:33,980
specific list of service, I have a text

34
00:01:33,980 --> 00:01:35,910
file with service in, so I'm going to get

35
00:01:35,910 --> 00:01:38,380
the names of those by using Get‑Content.

36
00:01:38,380 --> 00:01:40,940
And then I want to go and get the service

37
00:01:40,940 --> 00:01:43,890
name, so the WinRM, so the Windows Remote

38
00:01:43,890 --> 00:01:45,610
Management one. And then I'm going to

39
00:01:45,610 --> 00:01:48,110
create a job name, throttle it down to a

40
00:01:48,110 --> 00:01:51,540
specific limit, and just send it as a job.

41
00:01:51,540 --> 00:01:53,660
So in actual fact, even though there's two

42
00:01:53,660 --> 00:01:57,060
core ways of creating jobs, Start‑Job and

43
00:01:57,060 --> 00:02:00,940
the & parameter, we can also utilize the

44
00:02:00,940 --> 00:02:04,000
Invoke‑Command and the property for ‑AsJob.

