1
00:00:00,940 --> 00:00:02,930
Let's get stuck right in taking a look at

2
00:00:02,930 --> 00:00:04,630
working with package management and

3
00:00:04,630 --> 00:00:07,660
repositories. We are back at the trusty

4
00:00:07,660 --> 00:00:10,280
PowerShell prompt here, and if we start by

5
00:00:10,280 --> 00:00:12,160
running Get‑Command ‑Module

6
00:00:12,160 --> 00:00:14,470
PackageManagement, we'll see the list of

7
00:00:14,470 --> 00:00:16,540
PowerShell commands that can be used to

8
00:00:16,540 --> 00:00:18,830
discover and manage software packages,

9
00:00:18,830 --> 00:00:20,320
which hooks directly into the

10
00:00:20,320 --> 00:00:22,610
PackageManagement core framework we took a

11
00:00:22,610 --> 00:00:25,540
look at in the previous clip. Out of these

12
00:00:25,540 --> 00:00:28,260
commands, I'd like to run just one, which

13
00:00:28,260 --> 00:00:31,130
is Get‑PackageProvider. And we're returned

14
00:00:31,130 --> 00:00:33,040
with a list of the default providers that

15
00:00:33,040 --> 00:00:35,360
are installed and configured. Now,

16
00:00:35,360 --> 00:00:37,320
thinking back to the image we looked at in

17
00:00:37,320 --> 00:00:39,300
the previous clip, there were a number of

18
00:00:39,300 --> 00:00:41,320
providers that were colored with green,

19
00:00:41,320 --> 00:00:43,280
meaning they were there by default. But,

20
00:00:43,280 --> 00:00:45,890
we're only seeing two of them here. If I

21
00:00:45,890 --> 00:00:47,920
were to run this same command in Windows

22
00:00:47,920 --> 00:00:50,560
PowerShell, I'd see some other providers

23
00:00:50,560 --> 00:00:54,260
like MSI, programs, etc. This is because

24
00:00:54,260 --> 00:00:56,880
we're running PowerShell 7, and I don't

25
00:00:56,880 --> 00:00:58,430
believe it yet supports some of the other

26
00:00:58,430 --> 00:01:01,080
package providers. But that's okay because

27
00:01:01,080 --> 00:01:02,840
the one that we're interested in is

28
00:01:02,840 --> 00:01:04,890
PowerShellGet, and this is what we're

29
00:01:04,890 --> 00:01:06,620
going to focus on for the rest of this

30
00:01:06,620 --> 00:01:09,390
course. I do also want to quickly point

31
00:01:09,390 --> 00:01:11,150
out that with the PowerShell 7

32
00:01:11,150 --> 00:01:14,040
installation comes this NuGet provider.

33
00:01:14,040 --> 00:01:16,950
NuGet is the package manager for .NET, and

34
00:01:16,950 --> 00:01:18,810
PowerShell is heavily built on the .NET

35
00:01:18,810 --> 00:01:21,500
Framework. If you're following along, you

36
00:01:21,500 --> 00:01:23,660
probably have this installed already, but

37
00:01:23,660 --> 00:01:25,530
if you don't, the first time you try and

38
00:01:25,530 --> 00:01:27,440
install a module from the gallery you'll

39
00:01:27,440 --> 00:01:29,520
get asked to install NuGet. So if you get

40
00:01:29,520 --> 00:01:32,660
that prompt, that's okay to approve. Let's

41
00:01:32,660 --> 00:01:34,560
take a look at what commands are in that

42
00:01:34,560 --> 00:01:36,490
PowerShellGet module by running

43
00:01:36,490 --> 00:01:39,840
Get‑Command ‑Module PowerShellGet.

44
00:01:39,840 --> 00:01:42,440
Alrighty, there we go. There are some

45
00:01:42,440 --> 00:01:44,170
commands here that you are going to get

46
00:01:44,170 --> 00:01:46,390
very familiar with when you start working

47
00:01:46,390 --> 00:01:48,520
with PowerShell modules as these are the

48
00:01:48,520 --> 00:01:50,390
commands that you will use to both

49
00:01:50,390 --> 00:01:52,700
discover modules in repositories, and then

50
00:01:52,700 --> 00:01:55,640
install and manage them on your machine.

51
00:01:55,640 --> 00:01:58,360
If I run Get‑PSRepository with no

52
00:01:58,360 --> 00:02:00,810
parameters, PowerShell will return a list

53
00:02:00,810 --> 00:02:02,490
of the registered repositories on my

54
00:02:02,490 --> 00:02:05,320
machine. As I suspected, there's only one

55
00:02:05,320 --> 00:02:06,840
result, which is for the PowerShell

56
00:02:06,840 --> 00:02:09,000
Gallery, which is that default gallery

57
00:02:09,000 --> 00:02:12,080
owned and hosted by Microsoft. Do note

58
00:02:12,080 --> 00:02:14,550
here that it is actually Untrusted by

59
00:02:14,550 --> 00:02:16,600
default, and you'll see in the next clip

60
00:02:16,600 --> 00:02:18,600
when we try to install a module that we

61
00:02:18,600 --> 00:02:20,700
have to accept a prompt to confirm that we

62
00:02:20,700 --> 00:02:22,580
trust that repository and that we want to

63
00:02:22,580 --> 00:02:24,980
use it. I'd like to show you that you can

64
00:02:24,980 --> 00:02:26,740
add additional repositories to have at

65
00:02:26,740 --> 00:02:29,140
your disposal, and these could be private

66
00:02:29,140 --> 00:02:32,540
repositories or other public repositories.

67
00:02:32,540 --> 00:02:34,710
There's an article here on the Microsoft

68
00:02:34,710 --> 00:02:36,590
Docs website that I want to draw your

69
00:02:36,590 --> 00:02:38,870
attention to named Working with Private

70
00:02:38,870 --> 00:02:41,670
PowerShellGet Repositories. If I scroll

71
00:02:41,670 --> 00:02:44,080
down a little, this section titled Local

72
00:02:44,080 --> 00:02:46,610
repository types outlines the two types of

73
00:02:46,610 --> 00:02:48,490
local PowerShell repositories that you can

74
00:02:48,490 --> 00:02:51,180
deploy, the first being a NuGet‑based

75
00:02:51,180 --> 00:02:53,240
server, which has very similar

76
00:02:53,240 --> 00:02:55,740
functionality to the PowerShell Gallery,

77
00:02:55,740 --> 00:02:58,130
and the second being a stock standard File

78
00:02:58,130 --> 00:03:00,940
Share. Each of these have advantages and

79
00:03:00,940 --> 00:03:03,390
disadvantages, as you can see outlined

80
00:03:03,390 --> 00:03:05,620
here. And if you are looking seriously

81
00:03:05,620 --> 00:03:07,670
into having a private repository for your

82
00:03:07,670 --> 00:03:10,240
company or organization, I'd strongly

83
00:03:10,240 --> 00:03:11,770
recommend you come here to check out this

84
00:03:11,770 --> 00:03:13,930
page to see which one is best going to

85
00:03:13,930 --> 00:03:16,550
suit your needs. Let's jump back over the

86
00:03:16,550 --> 00:03:18,730
PowerShell and run through creating a file

87
00:03:18,730 --> 00:03:20,880
share‑based repository. I'm going to

88
00:03:20,880 --> 00:03:23,080
create a new folder on this computer by

89
00:03:23,080 --> 00:03:25,150
running New‑Item in the ‑Path

90
00:03:25,150 --> 00:03:29,050
C:\LocalPSRepo, and then setting the

91
00:03:29,050 --> 00:03:32,230
‑ItemType as a Directory. From there, I

92
00:03:32,230 --> 00:03:34,040
can create a share on that folder by

93
00:03:34,040 --> 00:03:36,790
running New‑SmbShare. For the ‑Name, I'll

94
00:03:36,790 --> 00:03:39,860
just call it LocalPSRepo, and the ‑Path

95
00:03:39,860 --> 00:03:44,290
was C:\LocalPSRepo. We now have a file

96
00:03:44,290 --> 00:03:46,660
share that can be used as the target for a

97
00:03:46,660 --> 00:03:49,290
private PowerShell repository. And we can

98
00:03:49,290 --> 00:03:51,590
register that into our session by running

99
00:03:51,590 --> 00:03:55,960
Register‑PSRepository, ‑Name LocalPSRepo.

100
00:03:55,960 --> 00:03:57,530
Now that name doesn't have to be the same

101
00:03:57,530 --> 00:03:59,450
name as the share, I'm just doing that

102
00:03:59,450 --> 00:04:01,640
because I'm not a creative person.

103
00:04:01,640 --> 00:04:04,210
‑SourceLocation is the share path, so

104
00:04:04,210 --> 00:04:08,980
that's \\localhost\LocalPSRepo. And the

105
00:04:08,980 --> 00:04:11,090
‑ScriptSourceLocation, again, is

106
00:04:11,090 --> 00:04:16,510
\\localhost\LocalPSRepo. I'm also going to

107
00:04:16,510 --> 00:04:18,940
use the InstallationPolicy parameter to

108
00:04:18,940 --> 00:04:20,960
set this as a trusted repository from the

109
00:04:20,960 --> 00:04:24,430
get‑go. And if we execute that, as I said

110
00:04:24,430 --> 00:04:26,760
earlier, no news is usually good news, so

111
00:04:26,760 --> 00:04:30,000
let's run Get‑PSRepository again. And yep,

112
00:04:30,000 --> 00:04:32,710
there we can see that LocalPSRepo is now

113
00:04:32,710 --> 00:04:35,560
listed as a PowerShell repository. What

114
00:04:35,560 --> 00:04:38,210
does this mean? Well, it means we can now

115
00:04:38,210 --> 00:04:40,420
use other commands from the PowerShellGet

116
00:04:40,420 --> 00:04:42,780
module, and they will look not only in the

117
00:04:42,780 --> 00:04:44,940
PowerShell Gallery online, but they will

118
00:04:44,940 --> 00:04:47,530
also work with modules that may be located

119
00:04:47,530 --> 00:04:50,450
in that private repository. Now, there's

120
00:04:50,450 --> 00:04:52,040
obviously none in there at the moment

121
00:04:52,040 --> 00:04:54,370
because I just created it. But imagine if

122
00:04:54,370 --> 00:04:56,670
this was a private repository for a large

123
00:04:56,670 --> 00:04:58,940
company like Globomantics, and they

124
00:04:58,940 --> 00:05:00,910
published all of their privately developed

125
00:05:00,910 --> 00:05:03,350
modules here. I'd be able to use those

126
00:05:03,350 --> 00:05:05,880
same commands from PowerShellGet to find

127
00:05:05,880 --> 00:05:08,240
and install modules from any repo,

128
00:05:08,240 --> 00:05:11,270
including this private one. Before we move

129
00:05:11,270 --> 00:05:13,250
on, the last thing I want to demonstrate

130
00:05:13,250 --> 00:05:15,150
is that you can change the installation

131
00:05:15,150 --> 00:05:17,450
policy of a repository by using

132
00:05:17,450 --> 00:05:20,940
Set‑PSRepository. So, I could set the name

133
00:05:20,940 --> 00:05:23,390
as the PSGallery, and then configure the

134
00:05:23,390 --> 00:05:26,360
installation policy to be trusted. If I

135
00:05:26,360 --> 00:05:29,080
run Get‑PSRepository again, you will

136
00:05:29,080 --> 00:05:30,500
notice that the policy has changed to

137
00:05:30,500 --> 00:05:33,090
Trusted. I'm going to drop that back to

138
00:05:33,090 --> 00:05:34,980
Untrusted because I want to show you the

139
00:05:34,980 --> 00:05:37,130
default behavior when we start finding and

140
00:05:37,130 --> 00:05:41,000
installing modules, which is coming up next.

