1
00:00:00,520 --> 00:00:02,240
So to get started, let's look at how we

2
00:00:02,240 --> 00:00:05,010
execute commands on remote computers.

3
00:00:05,010 --> 00:00:06,560
Well, first off, there are some core

4
00:00:06,560 --> 00:00:09,430
system requirements for utilizing what's

5
00:00:09,430 --> 00:00:11,830
referred to as PowerShell remoting. The

6
00:00:11,830 --> 00:00:14,110
first one is PowerShell version 3 or

7
00:00:14,110 --> 00:00:16,530
higher. Luckily, we're using PowerShell 7,

8
00:00:16,530 --> 00:00:18,900
so we'll be utilizing the right version.

9
00:00:18,900 --> 00:00:21,910
Then, the Microsoft.NET Framework 4.0 or

10
00:00:21,910 --> 00:00:24,200
higher, which for Windows 10 is perfectly

11
00:00:24,200 --> 00:00:27,250
fine, it will be at least 4.7 or higher.

12
00:00:27,250 --> 00:00:29,520
Then, of course, Windows Remote Management

13
00:00:29,520 --> 00:00:33,230
3.0. So three core system requirements for

14
00:00:33,230 --> 00:00:37,000
any type of PowerShell remoting. The

15
00:00:37,000 --> 00:00:38,820
second thing we need is the correct user

16
00:00:38,820 --> 00:00:41,080
permissions. So in order for this to work,

17
00:00:41,080 --> 00:00:42,390
you'll need to have an administrator

18
00:00:42,390 --> 00:00:44,330
credential in order to operate the

19
00:00:44,330 --> 00:00:46,720
PowerShell remotely. You'll need to have

20
00:00:46,720 --> 00:00:49,000
your account or the account that you use

21
00:00:49,000 --> 00:00:51,570
be part of the administrators group on

22
00:00:51,570 --> 00:00:55,010
both the local and those remote machines,

23
00:00:55,010 --> 00:00:57,240
or at least be able to provide credentials

24
00:00:57,240 --> 00:00:59,280
when you get prompted, or at least provide

25
00:00:59,280 --> 00:01:03,320
them in the commands. Now you can always

26
00:01:03,320 --> 00:01:05,310
see the types of commands that can be

27
00:01:05,310 --> 00:01:07,780
utilized for remoting by executing a

28
00:01:07,780 --> 00:01:10,100
simple command. So what we're looking for

29
00:01:10,100 --> 00:01:11,310
here is we're going to use the

30
00:01:11,310 --> 00:01:13,600
Get‑Command, and then we're going to look

31
00:01:13,600 --> 00:01:16,480
inside the parameter keys for something

32
00:01:16,480 --> 00:01:19,230
that says ComputerName. This will display

33
00:01:19,230 --> 00:01:22,930
a list of the commands that will allow you

34
00:01:22,930 --> 00:01:25,980
to pass a computer name. Not every

35
00:01:25,980 --> 00:01:27,800
PowerShell command that you'll ever want

36
00:01:27,800 --> 00:01:31,020
to utilize can be used necessarily with a

37
00:01:31,020 --> 00:01:33,040
computer name parameter. Now, does that

38
00:01:33,040 --> 00:01:35,860
mean it can't be used remotely? No, it

39
00:01:35,860 --> 00:01:38,340
just means that you, when you initiate the

40
00:01:38,340 --> 00:01:41,750
connection, you can't use that command to

41
00:01:41,750 --> 00:01:44,220
target a computer, but you can bundle it

42
00:01:44,220 --> 00:01:47,870
as part of a job. So the most common way

43
00:01:47,870 --> 00:01:50,150
that we would connect to remote service is

44
00:01:50,150 --> 00:01:51,750
by using what's called an interactive

45
00:01:51,750 --> 00:01:54,310
PowerShell session to create a remote

46
00:01:54,310 --> 00:01:55,960
interactive PowerShell session, we're

47
00:01:55,960 --> 00:01:58,570
going to use Enter‑PSSession, and then you

48
00:01:58,570 --> 00:02:00,890
can pass the computer name for this one.

49
00:02:00,890 --> 00:02:03,930
You can also do New‑PSSession and do a

50
00:02:03,930 --> 00:02:06,410
similar thing, but Enter will actually

51
00:02:06,410 --> 00:02:09,870
connect you in and then allow you to see

52
00:02:09,870 --> 00:02:13,620
that response back. We could also then

53
00:02:13,620 --> 00:02:15,630
exit those PS sessions, and that's

54
00:02:15,630 --> 00:02:17,520
important, because when you create the

55
00:02:17,520 --> 00:02:19,840
sessions remotely, you'll need to clear

56
00:02:19,840 --> 00:02:22,640
those sessions back down. We also have the

57
00:02:22,640 --> 00:02:25,390
ability using the NewPSSession to create

58
00:02:25,390 --> 00:02:27,150
what's referred to as a persistent,

59
00:02:27,150 --> 00:02:29,990
non‑interactive PowerShell. Now, what that

60
00:02:29,990 --> 00:02:32,700
means is that that allows me to pass that

61
00:02:32,700 --> 00:02:35,930
session to an Invoke‑Command request using

62
00:02:35,930 --> 00:02:39,270
the session property. It does not return

63
00:02:39,270 --> 00:02:41,940
effectively the command prompt back to me,

64
00:02:41,940 --> 00:02:44,560
it just creates a session where I can push

65
00:02:44,560 --> 00:02:48,150
things into it. So if we had that

66
00:02:48,150 --> 00:02:50,130
persistent kind of non‑interactive

67
00:02:50,130 --> 00:02:52,070
PowerShell, we could then say

68
00:02:52,070 --> 00:02:55,450
Invoke‑Command, use this session, and then

69
00:02:55,450 --> 00:03:00,000
our script block can be any kind of command that we wish to utilize.

