1
00:00:02,440 --> 00:00:06,640
We'll start with creating PSDrive in FileSystem provider.

2
00:00:06,640 --> 00:00:08,340
In the first example,

3
00:00:08,340 --> 00:00:14,340
I'll create a temporary PSDrive which will map to a folder on my local machine.

4
00:00:14,340 --> 00:00:17,840
I'll take an example of Downloads folder path.

5
00:00:17,840 --> 00:00:22,700
So what we will be doing is we will create a new PSDrive that

6
00:00:22,700 --> 00:00:25,710
will map to the current user's Downloads folder.

7
00:00:25,710 --> 00:00:29,840
First, I'll enter the command New‑PSDrive.

8
00:00:29,840 --> 00:00:35,000
I'll then use Name parameter to provide this drive a unique name.

9
00:00:35,000 --> 00:00:39,020
Since we are creating this drive to map it to Downloads folder,

10
00:00:39,020 --> 00:00:42,640
it makes sense to set the name as Downloads.

11
00:00:42,640 --> 00:00:44,940
Next, in the Root parameter,

12
00:00:44,940 --> 00:00:49,740
I'll enter the complete folder path where I want this drive to be mapped.

13
00:00:49,740 --> 00:00:53,950
In this case, I'll map to current user's Downloads folder.

14
00:00:53,950 --> 00:00:59,010
I'll then specify the PSProvider where I want this drive to get created.

15
00:00:59,010 --> 00:01:03,140
Since it's a folder that I'm creating on my logical drive,

16
00:01:03,140 --> 00:01:05,640
it will be FileSystem provider.

17
00:01:05,640 --> 00:01:10,740
As soon as I hit Enter, we can see that the new PSDrive got created.

18
00:01:10,740 --> 00:01:15,210
This will also list some of the properties of this newly created PSDrive.

19
00:01:15,210 --> 00:01:19,520
We can see Name, Provider, Root property,

20
00:01:19,520 --> 00:01:22,500
along with Used and Free space of the drive.

21
00:01:22,500 --> 00:01:29,840
Now when I run Get‑PSDrive command, this newly created drive will be listed.

22
00:01:29,840 --> 00:01:33,820
I will then use Set‑Location command and enter the name of

23
00:01:33,820 --> 00:01:36,960
this PSDrive to enter into this drive.

24
00:01:36,960 --> 00:01:41,650
I can then run any of the management commands that we saw earlier in

25
00:01:41,650 --> 00:01:45,450
this module to manage files and folders in this drive.

26
00:01:45,450 --> 00:01:47,420
Just to demonstrate,

27
00:01:47,420 --> 00:01:50,720
I'll run Get‑ChildItem command that will list all the

28
00:01:50,720 --> 00:01:53,440
files and folders in this path.

29
00:01:53,440 --> 00:01:56,550
I'll quickly open another PowerShell session. To

30
00:01:56,550 --> 00:01:59,150
differentiate between the two PowerShell consoles,

31
00:01:59,150 --> 00:02:03,930
I have used different text color in this window. I'll now run Get‑PSDrive

32
00:02:03,930 --> 00:02:10,490
command. Here we can see that the Downloads PSDrive that we created in

33
00:02:10,490 --> 00:02:13,640
another PowerShell session does not appear.

34
00:02:13,640 --> 00:02:17,200
This is because temporary PSDrives are sessions specific.

35
00:02:17,200 --> 00:02:21,200
They will be available to use only in the session they are

36
00:02:21,200 --> 00:02:24,120
created. In the next example,

37
00:02:24,120 --> 00:02:29,860
I'll create a persistent PSDrive and map Shared folder on a network.

38
00:02:29,860 --> 00:02:33,470
I have already created a Shared folder on DC server,

39
00:02:33,470 --> 00:02:36,440
which we will be using in this example.

40
00:02:36,440 --> 00:02:40,510
Remember a few rules of persistent drives. Persistent drives

41
00:02:40,510 --> 00:02:45,170
require a drive letter to be assigned instead of a name. Persistent

42
00:02:45,170 --> 00:02:48,340
drives cannot be mapped to a local folder.

43
00:02:48,340 --> 00:02:52,830
Persistent drives are available across PowerShell sessions.

44
00:02:52,830 --> 00:02:56,920
I'll run New‑PSDrive command. At first, just to see what

45
00:02:56,920 --> 00:03:00,650
happens, I will intentionally enter the name instead of a

46
00:03:00,650 --> 00:03:03,140
drive letter in the name parameter.

47
00:03:03,140 --> 00:03:09,030
I'll enter SharedPSDrive. I'll then enter local path instead of network path

48
00:03:09,030 --> 00:03:16,020
in the Root parameter. I'll enter local folder path C:/Users. I'll enter

49
00:03:16,020 --> 00:03:20,840
FileSystem in PSProvider parameter, and to make this drive as a persistent

50
00:03:20,840 --> 00:03:24,440
drive, I'll add Persist parameter at the end.

51
00:03:24,440 --> 00:03:27,940
When I execute this command, we get an error.

52
00:03:27,940 --> 00:03:32,410
The error says when you use the Persist parameter the root must be

53
00:03:32,410 --> 00:03:35,430
a file system location on a remote computer.

54
00:03:35,430 --> 00:03:39,940
This proves that a persistent drive cannot be mapped to a local folder.

55
00:03:39,940 --> 00:03:46,450
I'll now replace the path with the Shared folder that I created. I'll enter

56
00:03:46,450 --> 00:03:50,040
DC\Shared. Again, when I run the command we get an error.

57
00:03:50,040 --> 00:03:55,340
The error basically says that a drive letter should be used to map folder.

58
00:03:55,340 --> 00:04:00,540
This proves that a persistent drive can be mapped only to a drive letter.

59
00:04:00,540 --> 00:04:06,140
Now I'll replace the value in the name parameter with K drive. You can use any

60
00:04:06,140 --> 00:04:11,650
available drive letter here. When I hit Enter, the command succeeds and the

61
00:04:11,650 --> 00:04:15,970
drive gets created. When I run Get‑PSDrive command,

62
00:04:15,970 --> 00:04:21,660
we can see that K drive is created. We can also see Downloads PSDrive

63
00:04:21,660 --> 00:04:25,140
that we created earlier in this PowerShell session.

64
00:04:25,140 --> 00:04:30,940
Now, when I switch to another PowerShell session and run Get‑PSDrive command,

65
00:04:30,940 --> 00:04:34,850
we can see that unlike temporary drives, K drive,

66
00:04:34,850 --> 00:04:38,640
which is a persistent drive, is available to us.

67
00:04:38,640 --> 00:04:43,830
We can also enter into this drive using Set‑Location command. This is what

68
00:04:43,830 --> 00:04:48,880
persistent drives are meant for. You can create it in one PowerShell session and

69
00:04:48,880 --> 00:04:52,340
can use it in some other PowerShell session as well.

70
00:04:52,340 --> 00:04:55,780
This persistent drive, however, will not be available

71
00:04:55,780 --> 00:04:58,540
to us when the system restarts.

72
00:04:58,540 --> 00:04:59,530
However,

73
00:04:59,530 --> 00:05:01,990
we have a workaround if you want to retain the

74
00:05:01,990 --> 00:05:04,440
drive in every PowerShell session,

75
00:05:04,440 --> 00:05:08,260
even if the system restarts. You might have heard about PowerShell

76
00:05:08,260 --> 00:05:12,140
profiles. If you're not aware about PowerShell profiles,

77
00:05:12,140 --> 00:05:15,290
just remember that it's a PowerShell script that runs

78
00:05:15,290 --> 00:05:18,570
whenever PowerShell starts. You can customize your

79
00:05:18,570 --> 00:05:21,160
PowerShell environment by adding commands,

80
00:05:21,160 --> 00:05:24,150
functions, variables, modules,

81
00:05:24,150 --> 00:05:27,810
and PowerShell drives and PowerShell profiles, so that

82
00:05:27,810 --> 00:05:30,580
whenever a new PowerShell session is launched,

83
00:05:30,580 --> 00:05:35,790
all the configured settings in PowerShell profile will get loaded. Now

84
00:05:35,790 --> 00:05:38,850
there are different types of PowerShell profiles that you can

85
00:05:38,850 --> 00:05:43,960
configure, but we won't discuss about these types in this course, as

86
00:05:43,960 --> 00:05:47,750
this is beyond the scope of this course. You can learn more about

87
00:05:47,750 --> 00:05:50,540
PowerShell profiles from this link.

88
00:05:50,540 --> 00:05:51,630
For this demo,

89
00:05:51,630 --> 00:05:54,880
I'll create PowerShell profile for all users and all

90
00:05:54,880 --> 00:05:59,350
hosts. You will see profile.ps1 file inside Program

91
00:05:59,350 --> 00:06:03,330
Files\PowerShell\7 folder. By default,

92
00:06:03,330 --> 00:06:08,970
it is not present, and in that case you can create a new one. I'll quickly

93
00:06:08,970 --> 00:06:13,830
open this file and copy the command that will create a new persistent

94
00:06:13,830 --> 00:06:18,940
PSDrive and map it to the DC server's Shared folder.

95
00:06:18,940 --> 00:06:23,330
Note that I am mapping this folder to S drive. I'll quickly

96
00:06:23,330 --> 00:06:27,040
restart my system, and once the system restarts,

97
00:06:27,040 --> 00:06:31,660
we will see whether the PSDrive got created. The system is now

98
00:06:31,660 --> 00:06:37,470
rebooted. I'll now open PowerShell. We can see a message that

99
00:06:37,470 --> 00:06:40,540
says PowerShell profile has been loaded.

100
00:06:40,540 --> 00:06:44,140
This profile has added the PSDrive.

101
00:06:44,140 --> 00:06:46,540
When I run Get‑PSDrive command,

102
00:06:46,540 --> 00:06:50,430
we can see that the new PSDrive has been added that

103
00:06:50,430 --> 00:06:53,720
maps to a Shared folder on DC server.

104
00:06:53,720 --> 00:07:01,000
This is how you can deal with persistent PSDrives that you want to retain even after the system reboots.

