1
00:00:00,390 --> 00:00:02,490
So how do we create remote background

2
00:00:02,490 --> 00:00:07,180
jobs? Well, this is done first by

3
00:00:07,180 --> 00:00:10,250
executing the computer name. So we'll need

4
00:00:10,250 --> 00:00:12,400
to pass a computer name as part of the

5
00:00:12,400 --> 00:00:15,370
command and say, I want to talk to domain

6
00:00:15,370 --> 00:00:19,290
controller 1, SQL server 2, etc. We then

7
00:00:19,290 --> 00:00:21,090
have an optional parameter, which will be

8
00:00:21,090 --> 00:00:24,380
the credential. So we'll say, domain/user

9
00:00:24,380 --> 00:00:26,770
to that machine or whatever account it

10
00:00:26,770 --> 00:00:28,890
needs to be. And then, of course, we have

11
00:00:28,890 --> 00:00:31,320
the script block parameter, which is what

12
00:00:31,320 --> 00:00:35,940
we wish to execute on that remote machine.

13
00:00:35,940 --> 00:00:37,710
So some examples of this, if we wish to

14
00:00:37,710 --> 00:00:40,060
run a command on a remote computer, we're

15
00:00:40,060 --> 00:00:41,960
going to use the Invoke‑Command again,

16
00:00:41,960 --> 00:00:44,410
we'll pass the computer name, we'll pass a

17
00:00:44,410 --> 00:00:46,680
credential this time. Which you may not

18
00:00:46,680 --> 00:00:49,690
have to, because if you're on a member

19
00:00:49,690 --> 00:00:51,730
server, it's part of a domain. And you're

20
00:00:51,730 --> 00:00:54,020
already logged in with valid credentials

21
00:00:54,020 --> 00:00:55,980
that would allow you to log into the other

22
00:00:55,980 --> 00:00:58,010
machines. You won't ever have to pass

23
00:00:58,010 --> 00:01:00,540
credential, but sometimes you may need to.

24
00:01:00,540 --> 00:01:02,590
And then, of course, our ‑ScriptBlock is

25
00:01:02,590 --> 00:01:05,160
the execution wish to send. So we're going

26
00:01:05,160 --> 00:01:08,150
to say go to that computer and retrieve

27
00:01:08,150 --> 00:01:11,230
the Get‑Process. The other option is we

28
00:01:11,230 --> 00:01:13,700
can create remote background jobs on those

29
00:01:13,700 --> 00:01:16,070
computers by using a different mechanism.

30
00:01:16,070 --> 00:01:18,980
So instead of me running on one single

31
00:01:18,980 --> 00:01:22,180
machine, I'm going to say, execute this on

32
00:01:22,180 --> 00:01:24,770
multiple machines. So I'm going to say, go

33
00:01:24,770 --> 00:01:27,360
and retrieve me a new non‑interactive

34
00:01:27,360 --> 00:01:29,560
PowerShell session for these specific

35
00:01:29,560 --> 00:01:31,530
machines. And then I'm going to say,

36
00:01:31,530 --> 00:01:34,250
invoke the command, and you'll notice I'm

37
00:01:34,250 --> 00:01:37,570
now using ‑AsJob. So in the first example,

38
00:01:37,570 --> 00:01:39,780
I'm just executing a command. I'm not

39
00:01:39,780 --> 00:01:42,470
really creating a job. But in the second

40
00:01:42,470 --> 00:01:45,260
one, I'm using that ‑AsJob parameter to

41
00:01:45,260 --> 00:01:47,990
change what was originally created to be

42
00:01:47,990 --> 00:01:51,000
jobs now, inside those PowerShell sessions.

