1
00:00:00,040 --> 00:00:01,040
Now,

2
00:00:01,040 --> 00:00:04,600
an interesting use case that we often find when working with

3
00:00:04,600 --> 00:00:07,600
PowerShell is the ability to move files,

4
00:00:07,600 --> 00:00:10,540
and objects, and content around.

5
00:00:10,540 --> 00:00:15,750
Now copying files can be done either manually or you can do script

6
00:00:15,750 --> 00:00:19,330
execution and you can use a network share for example.

7
00:00:19,330 --> 00:00:23,790
So you know, maybe we're using the Active Directory server share,

8
00:00:23,790 --> 00:00:28,340
have some files in there, and we need to copy them from one place to another.

9
00:00:28,340 --> 00:00:33,680
We also can use script execution for remote PowerShell as well.

10
00:00:33,680 --> 00:00:37,680
So we can either manually copy files, write PowerShell to copy files,

11
00:00:37,680 --> 00:00:41,080
or what would be helpful is if I need to copy,

12
00:00:41,080 --> 00:00:41,460
let's say,

13
00:00:41,460 --> 00:00:46,300
I want to copy a series of PowerShell script files to the

14
00:00:46,300 --> 00:00:50,590
remote server to execute them and do that every time we

15
00:00:50,590 --> 00:00:52,920
connect to make sure they're updated, then,

16
00:00:52,920 --> 00:00:53,210
of course,

17
00:00:53,210 --> 00:00:57,720
I don't want to be manually having to copy six files over to here

18
00:00:57,720 --> 00:01:02,210
because what happens if you are in a secure environment and don't

19
00:01:02,210 --> 00:01:06,840
actually have access to UNC or shared paths.

20
00:01:06,840 --> 00:01:10,360
To achieve this, we can use the Copy‑Item command.

21
00:01:10,360 --> 00:01:15,840
This will allow us to copy an item from one location to another.

22
00:01:15,840 --> 00:01:20,840
Now the cmdlet doesn't cut or delete the items, it literally just copies.

23
00:01:20,840 --> 00:01:25,540
You're able to copy and rename items as part of the same command.

24
00:01:25,540 --> 00:01:30,340
You can use it locally or remotely, and to do it remotely,

25
00:01:30,340 --> 00:01:37,440
we can utilize ‑ToSession to work within the construct of remote computers.

26
00:01:37,440 --> 00:01:38,890
So what does this look like?

27
00:01:38,890 --> 00:01:39,680
Well, let's have a look.

28
00:01:39,680 --> 00:01:43,340
So, I have a location and a destination.

29
00:01:43,340 --> 00:01:46,820
So my location is on my Active Directory server,

30
00:01:46,820 --> 00:01:50,710
I have a Files share, and then my destination is I wish to store

31
00:01:50,710 --> 00:01:55,740
them locally in a new folder called C:\Files.

32
00:01:55,740 --> 00:02:01,440
We can use Copy‑Item, so Path, which would be the location,

33
00:02:01,440 --> 00:02:06,690
\* because I want to move everything, and then I have the Destination option,

34
00:02:06,690 --> 00:02:08,940
which lets me just say dump them over there.

35
00:02:08,940 --> 00:02:11,640
So I can run this on my local machine.

36
00:02:11,640 --> 00:02:14,480
So I could go into my admin workstation,

37
00:02:14,480 --> 00:02:16,820
do the same process, and say run that command,

38
00:02:16,820 --> 00:02:19,640
and it will copy the files from the network share

39
00:02:19,640 --> 00:02:22,640
into that folder on my machine.

40
00:02:22,640 --> 00:02:25,410
Now if you want to copy the files to a remote computer

41
00:02:25,410 --> 00:02:28,470
that you may not have UNC access to, then,

42
00:02:28,470 --> 00:02:30,770
of course, we can create a session first.

43
00:02:30,770 --> 00:02:33,640
So we're going to use New‑PSSession,

44
00:02:33,640 --> 00:02:35,840
which is the Active Directory server at this point.

45
00:02:35,840 --> 00:02:39,950
I'm going to say Copy‑Item with a Path of the files to get to,

46
00:02:39,950 --> 00:02:41,380
set the Destination,

47
00:02:41,380 --> 00:02:46,000
and then you'll see at the end there we use ToSession and we tell it to

48
00:02:46,000 --> 00:02:50,640
send this command down the session that we created.

49
00:02:50,640 --> 00:02:56,410
So this means I can copy files from one machine through an existing

50
00:02:56,410 --> 00:03:00,410
PowerShell session and have them pop out on the other machine without

51
00:03:00,410 --> 00:03:05,440
actually having to have UNC or shared network access.

52
00:03:05,440 --> 00:03:07,650
So what's the use case for using this?

53
00:03:07,650 --> 00:03:11,190
Well, Globomantics is a highly secure environment,

54
00:03:11,190 --> 00:03:15,270
so for example, there's no network copying to specific servers.

55
00:03:15,270 --> 00:03:19,480
Maybe there'll be specific port restrictions as well.

56
00:03:19,480 --> 00:03:22,290
The core requirement is to copy custom PowerShell

57
00:03:22,290 --> 00:03:24,290
scripts to the remote computers.

58
00:03:24,290 --> 00:03:27,330
So that's the objective here, we want to be able to say,

59
00:03:27,330 --> 00:03:31,160
well those three member servers, we can't really copy things to them,

60
00:03:31,160 --> 00:03:34,440
but I want to somehow get those files to it.

61
00:03:34,440 --> 00:03:35,220
And then, of course,

62
00:03:35,220 --> 00:03:39,440
the requirement is for me as an admin to copy things like

63
00:03:39,440 --> 00:03:42,400
administration programs to the remote computers.

64
00:03:42,400 --> 00:03:45,580
So maybe we're trying to copy pieces that are part of,

65
00:03:45,580 --> 00:03:49,630
for example, Sysinternals, tools that we wish to utilize remotely.

66
00:03:49,630 --> 00:03:55,000
We can't get them to the machine, so we want to use PowerShell to be able to push them over there.

