1
00:00:00,340 --> 00:00:02,940
So let's go back into our Globomantics environment.

2
00:00:02,940 --> 00:00:06,540
We'll look at how we copy files to remote computers.

3
00:00:06,540 --> 00:00:10,340
We'll first create the remote PowerShell sessions that are required.

4
00:00:10,340 --> 00:00:12,670
Then, we'll execute the PowerShell scripts that are

5
00:00:12,670 --> 00:00:15,090
stored in that network share.

6
00:00:15,090 --> 00:00:17,830
And then we'll lastly look at how we copy files

7
00:00:17,830 --> 00:00:23,340
directly through that remote session.

8
00:00:23,340 --> 00:00:27,840
So now that we've been able to connect to the multiple machines and execute

9
00:00:27,840 --> 00:00:32,350
PowerShell scripts, what we want to do now is look at how we can get things

10
00:00:32,350 --> 00:00:36,980
to or files or objects copied to other machines.

11
00:00:36,980 --> 00:00:40,500
Now the first thing I want to do is obviously just remind us of how

12
00:00:40,500 --> 00:00:44,640
we make connections across to other locations.

13
00:00:44,640 --> 00:00:47,440
So the first thing I want to do is create a specific

14
00:00:47,440 --> 00:00:51,030
session to one of the remote machines.

15
00:00:51,030 --> 00:00:54,150
So I'm going to say New‑PSSession, and then, of course, if

16
00:00:54,150 --> 00:01:00,620
we go through our ‑ComputerName option, what we'll do is we'll use 10.0.0.10,

17
00:01:00,620 --> 00:01:04,770
which is one of our main machines, and we'll just click Enter.

18
00:01:04,770 --> 00:01:08,190
And, of course, remember if we get this error, we do need to make

19
00:01:08,190 --> 00:01:13,880
sure that our ‑Credential object is specified as $creds, and then

20
00:01:13,880 --> 00:01:15,640
that gives us our connection.

21
00:01:15,640 --> 00:01:21,010
So if I click $session, you can see I have a remote session that's available.

22
00:01:21,010 --> 00:01:22,820
Now, if you look carefully at the command,

23
00:01:22,820 --> 00:01:25,740
you remember that we created, obviously, a new

24
00:01:25,740 --> 00:01:27,970
PowerShell session using ‑Credential.

25
00:01:27,970 --> 00:01:30,430
Now, if we clear this, well, before we clear that,

26
00:01:30,430 --> 00:01:30,890
tell you what,

27
00:01:30,890 --> 00:01:35,570
let's just remove the PSSession that we created, and we'll

28
00:01:35,570 --> 00:01:40,940
say, Id of 69, and we'll get rid of that.

29
00:01:40,940 --> 00:01:44,810
Let's go back and look at how we can create that new PowerShell

30
00:01:44,810 --> 00:01:50,420
session and if we can pass Credssp to it because remember, we want to

31
00:01:50,420 --> 00:01:53,420
be able to execute the command on the other side, and we want to get

32
00:01:53,420 --> 00:01:55,540
past any of the security issues.

33
00:01:55,540 --> 00:01:59,140
So I'm going to say Credssp, so this is now going to

34
00:01:59,140 --> 00:02:02,070
create me my session. And sure enough,

35
00:02:02,070 --> 00:02:05,140
I've now got my session opened to that machine.

36
00:02:05,140 --> 00:02:08,330
So once we have that, we can then obviously invoke or

37
00:02:08,330 --> 00:02:11,840
execute commands on the other machine.

38
00:02:11,840 --> 00:02:14,590
So let's go back to our folder structure of scripts that we

39
00:02:14,590 --> 00:02:17,800
have. We originally looked at the Report option,

40
00:02:17,800 --> 00:02:22,310
but what about if I wanted to enable or perform a backup?

41
00:02:22,310 --> 00:02:26,110
So let me just right‑click on one of these files, and we'll

42
00:02:26,110 --> 00:02:31,590
say Open with Code. We'll say Open, so we can see. Now in the

43
00:02:31,590 --> 00:02:33,440
Install‑Backup PowerShell script,

44
00:02:33,440 --> 00:02:37,410
I want to install Windows‑Server‑Backup, and then

45
00:02:37,410 --> 00:02:40,060
force a restart on that computer.

46
00:02:40,060 --> 00:02:43,590
So this is utilizing PowerShell. Now what we can do is

47
00:02:43,590 --> 00:02:45,920
we could capture this command here,

48
00:02:45,920 --> 00:02:49,690
so I'm going to say Copy. We now have the session, so let's just

49
00:02:49,690 --> 00:02:54,590
invoke that command that we had in the PowerShell.

50
00:02:54,590 --> 00:02:57,430
Now, of course, we can reuse this existing session.

51
00:02:57,430 --> 00:03:00,740
So instead of saying ‑ComputerName, I can say ‑Session.

52
00:03:00,740 --> 00:03:02,470
Now, of course, when we utilize the session,

53
00:03:02,470 --> 00:03:05,770
we don't need to pass any credentials or anything like that because that was

54
00:03:05,770 --> 00:03:11,730
created as part of the initial session. We can then do ‑ScriptBlock, and I can

55
00:03:11,730 --> 00:03:15,540
paste my install backup, and I can press Enter.

56
00:03:15,540 --> 00:03:19,890
Now this has now gone ahead, and trying to execute that over there. It

57
00:03:19,890 --> 00:03:22,780
already says success because I've already run this in the past,

58
00:03:22,780 --> 00:03:25,040
so we didn't have to wait for it to run,

59
00:03:25,040 --> 00:03:28,780
but that command installs Windows‑Server‑Backup.

60
00:03:28,780 --> 00:03:34,270
So let's go back to my Visual Studio Code. My next command would be to restart,

61
00:03:34,270 --> 00:03:37,840
which I don't want to restart, so we can imagine that that's been done.

62
00:03:37,840 --> 00:03:42,610
So let's then go back to my Scripts directory, and we'll choose Backup,

63
00:03:42,610 --> 00:03:46,240
and we'll say Open with Code, and we'll open this again.

64
00:03:46,240 --> 00:03:48,230
And now this one's a little bit different.

65
00:03:48,230 --> 00:03:52,730
This one is going to retrieve the name of the computer, then set the path.

66
00:03:52,730 --> 00:03:56,420
Notice we're using the Active Directory server and a folder called Backup.

67
00:03:56,420 --> 00:04:01,580
So let me go into here and find that directory, so Backup, so

68
00:04:01,580 --> 00:04:05,480
there's my empty folder. And what it's going to do is go ahead

69
00:04:05,480 --> 00:04:07,930
and create a directory for this path,

70
00:04:07,930 --> 00:04:11,410
which will be basically the name of the machine in there.

71
00:04:11,410 --> 00:04:16,000
And then it will go ahead and create the policy, backing up the C:

72
00:04:16,000 --> 00:04:19,540
drive, and then storing that as a backup option.

73
00:04:19,540 --> 00:04:25,120
So, the use case here is that we want to run this script on a regular basis.

74
00:04:25,120 --> 00:04:27,840
So let's go back into here.

75
00:04:27,840 --> 00:04:32,680
And what we'll do is we can say Invoke‑Command, and I'm going to get

76
00:04:32,680 --> 00:04:36,930
rid of my ‑ScriptBlock here because we're going to use the ‑FilePath

77
00:04:36,930 --> 00:04:42,710
one. I need to put my ‑FilePath option. And then in the ‑FilePath, we

78
00:04:42,710 --> 00:04:45,630
can get the UNC path to that script.

79
00:04:45,630 --> 00:04:51,440
So let's go back to my Scripts one, and what we'll do here is say Backup.

80
00:04:51,440 --> 00:04:55,690
I'm going to select the UNC path, and then go here and paste

81
00:04:55,690 --> 00:04:58,540
that in, and then I can execute that command.

82
00:04:58,540 --> 00:05:00,900
Now this will go ahead. Notice, it's created my

83
00:05:00,900 --> 00:05:04,180
directory called TRAININGSRV01VM.

84
00:05:04,180 --> 00:05:08,690
So let's go back to my folder structure. We'll go back to 10.0.0.5 Backup.

85
00:05:08,690 --> 00:05:12,620
And sure enough, that folder is created. And if I waited and watched it,

86
00:05:12,620 --> 00:05:15,460
it would then start to load values into there.

87
00:05:15,460 --> 00:05:19,840
So this is now going to perform a backup of this machine

88
00:05:19,840 --> 00:05:22,810
directly into the Active Directory server.

89
00:05:22,810 --> 00:05:25,430
Now you might have to give it a few minutes to wait, but there you go.

90
00:05:25,430 --> 00:05:28,940
It just appeared, WindowsImageBackup,

91
00:05:28,940 --> 00:05:34,000
and it will continue to run as we need it to, so a fairly painless process.

