1
00:00:00,340 --> 00:00:07,240
So let's first focus on creating single and multiple remote sessions.

2
00:00:07,240 --> 00:00:11,970
So firstly we have the two different types here. So you can execute a

3
00:00:11,970 --> 00:00:16,890
single connection to a remote machine and it could be done using

4
00:00:16,890 --> 00:00:21,960
Enter‑PSSession or maybe New‑PSSession if you want it to, and then we have

5
00:00:21,960 --> 00:00:27,410
the idea of connecting to multiple machines at the same time, invoking

6
00:00:27,410 --> 00:00:32,690
multiple sessions, and that can be done using the Invoke‑Command where you

7
00:00:32,690 --> 00:00:38,240
provide the list of remote machines as kind of a parameter to say I want

8
00:00:38,240 --> 00:00:39,170
to execute this.

9
00:00:39,170 --> 00:00:42,830
So think about Globomantics kind of architecture here. So we have our

10
00:00:42,830 --> 00:00:46,550
workstation with our multiple machines, and of course we're going to

11
00:00:46,550 --> 00:00:51,600
expand our lab to add more servers, but effectively I can say go and

12
00:00:51,600 --> 00:00:53,260
connect to the Active Directory server,

13
00:00:53,260 --> 00:00:56,490
the file server, and all the other servers, and run this

14
00:00:56,490 --> 00:01:00,040
single command against all of them.

15
00:01:00,040 --> 00:01:03,800
From a single remote session perspective, we can enter the

16
00:01:03,800 --> 00:01:08,200
PowerShell session and we can create New‑PSSession, and that

17
00:01:08,200 --> 00:01:10,270
will start an interactive session.

18
00:01:10,270 --> 00:01:15,790
So commands get typed in your machine, so if I'm on the admin workstation,

19
00:01:15,790 --> 00:01:19,740
I'm going to type the syntax or the commands, whatever I need to

20
00:01:19,740 --> 00:01:24,740
do, on my machine, and it will be as if you are typing them on

21
00:01:24,740 --> 00:01:29,270
that other machine. You are limited to one interactive session

22
00:01:29,270 --> 00:01:32,790
at a time, so you can't, if it's a single remote session,

23
00:01:32,790 --> 00:01:35,230
you can't be kind of dropping in and out all the time.

24
00:01:35,230 --> 00:01:36,030
Either way,

25
00:01:36,030 --> 00:01:40,340
if you come out of one you have to connect to the other, but you only

26
00:01:40,340 --> 00:01:46,560
have one at a time. You would use the ComputerName variable as part of

27
00:01:46,560 --> 00:01:48,530
the way of connecting to a single machine.

28
00:01:48,530 --> 00:01:52,930
So you simply are saying Invoke‑Command or Enter‑PSSession or

29
00:01:52,930 --> 00:01:57,490
New‑PSSession ‑ComputerName, and then specifying that single

30
00:01:57,490 --> 00:02:02,690
computer name. Now to create multiple remote sessions, we're going

31
00:02:02,690 --> 00:02:07,310
to utilize New‑PSSession and Invoke‑Command that will let you

32
00:02:07,310 --> 00:02:09,740
create those multiple sessions.

33
00:02:09,740 --> 00:02:12,880
We populate the ‑ComputerName variable with

34
00:02:12,880 --> 00:02:16,440
effectively an array of computer names.

35
00:02:16,440 --> 00:02:18,140
The commands are the same,

36
00:02:18,140 --> 00:02:20,690
they're typed in the local computer, and it's as if they

37
00:02:20,690 --> 00:02:25,540
were typed on the other machine. And all commands execute

38
00:02:25,540 --> 00:02:28,140
on each of the remote computers.

39
00:02:28,140 --> 00:02:30,830
So if you have 10 computers you're connected to,

40
00:02:30,830 --> 00:02:37,640
then it will execute the command on all of those 10 machines one by one.

41
00:02:37,640 --> 00:02:39,680
Now, in order for us to achieve this,

42
00:02:39,680 --> 00:02:42,990
we've actually expanded the Globomantics lab.

43
00:02:42,990 --> 00:02:45,160
So let's look at how this kind of breaks down.

44
00:02:45,160 --> 00:02:47,060
So we have our Active Directory server,

45
00:02:47,060 --> 00:02:51,930
we have our file server, and then we've introduced some member servers

46
00:02:51,930 --> 00:02:55,890
into the equation, and you can see here I have Member Server 01, 02,

47
00:02:55,890 --> 00:03:00,640
and 03. Then I have my Admin Workstation.

48
00:03:00,640 --> 00:03:05,820
So in order for us to look at how we connect remotely and to execute commands,

49
00:03:05,820 --> 00:03:08,040
we've increased the number of servers.

50
00:03:08,040 --> 00:03:10,880
So the idea is here that me, as the administrator,

51
00:03:10,880 --> 00:03:14,710
I wish to execute a command across Active Directory,

52
00:03:14,710 --> 00:03:18,220
file server, and three more member servers,

53
00:03:18,220 --> 00:03:21,900
which is kind of normal when you're looking after multiple

54
00:03:21,900 --> 00:03:28,340
servers or a server farm within any organization.

55
00:03:28,340 --> 00:03:31,350
So let's look at how we create a single remote session.

56
00:03:31,350 --> 00:03:34,680
So it's really simple from a PowerShell perspective. We can

57
00:03:34,680 --> 00:03:40,070
either use Enter‑PSSession or New‑PSSession, and we simply pass

58
00:03:40,070 --> 00:03:43,190
the ComputerName, and the IP address used here is obviously the

59
00:03:43,190 --> 00:03:44,440
Active Directory server.

60
00:03:44,440 --> 00:03:49,820
Either of those will initiate a single one‑time session to be

61
00:03:49,820 --> 00:03:52,740
able to connect backwards and forwards.

62
00:03:52,740 --> 00:03:56,800
If I wanted to create multiple sessions, then let's say I created a

63
00:03:56,800 --> 00:03:59,820
variable here with the IP addresses or the names,

64
00:03:59,820 --> 00:04:05,440
you'll recognize those IP addresses, those are Member Server 01, 02, and 03.

65
00:04:05,440 --> 00:04:08,640
I can then say New‑PSSession,

66
00:04:08,640 --> 00:04:13,120
I can use ComputerName, and then you'll see I'm just going to pass the

67
00:04:13,120 --> 00:04:16,340
variable. Now notice I don't have to do a loop statement,

68
00:04:16,340 --> 00:04:18,810
I don't have to iterate through the IP addresses,

69
00:04:18,810 --> 00:04:25,210
it understands it and will connect to all three and create sessions.

70
00:04:25,210 --> 00:04:26,610
If I wanted to be really,

71
00:04:26,610 --> 00:04:30,220
really clever and create, effectively, persistent sessions,

72
00:04:30,220 --> 00:04:34,600
I could create PowerShell sessions for every one of those IP

73
00:04:34,600 --> 00:04:37,740
addresses and put them into their own variable.

74
00:04:37,740 --> 00:04:39,940
Now, what would be the advantage of that?

75
00:04:39,940 --> 00:04:40,230
Well,

76
00:04:40,230 --> 00:04:44,190
if we think back to when we talked about connecting back into

77
00:04:44,190 --> 00:04:47,100
sessions or creating persistent sessions,

78
00:04:47,100 --> 00:04:50,540
it's based around the session associated to a

79
00:04:50,540 --> 00:04:52,490
variable that we can call back into.

80
00:04:52,490 --> 00:04:58,830
So this would mean I would end up with $srv01, 02, and 03, each

81
00:04:58,830 --> 00:05:03,640
containing a PowerShell session that relates to the IP addresses

82
00:05:03,640 --> 00:05:09,000
that were passed as part of the ComputerName, allowing us to drop in and out much easily.

