1
00:00:00,940 --> 00:00:03,100
As I've mentioned a couple of times now,

2
00:00:03,100 --> 00:00:05,380
authors of PowerShell code will often

3
00:00:05,380 --> 00:00:07,780
release updates to their modules. This may

4
00:00:07,780 --> 00:00:09,990
be to fix bugs or introduce new

5
00:00:09,990 --> 00:00:12,690
functionality or features. Like any

6
00:00:12,690 --> 00:00:14,530
software you install, you'll want to make

7
00:00:14,530 --> 00:00:16,520
sure that you do regular maintenance on it

8
00:00:16,520 --> 00:00:18,760
to keep it patched and up to date. Let's

9
00:00:18,760 --> 00:00:20,370
dive into doing that with PowerShell

10
00:00:20,370 --> 00:00:23,460
modules. I'm going to install a different

11
00:00:23,460 --> 00:00:25,790
module from the PowerShell Gallery named

12
00:00:25,790 --> 00:00:29,320
posh‑ssh, which is a popular module for

13
00:00:29,320 --> 00:00:33,010
SSH and SCP connections to endpoints, and

14
00:00:33,010 --> 00:00:34,690
I'm going to refer to it moving forward

15
00:00:34,690 --> 00:00:38,190
simply as posh‑ssh. I happen to know that

16
00:00:38,190 --> 00:00:40,210
the most recent version on the gallery is

17
00:00:40,210 --> 00:00:42,850
2.2, but I'm going to use the required

18
00:00:42,850 --> 00:00:45,950
version parameter to install version 2.0

19
00:00:45,950 --> 00:00:48,370
on my computer. The module that we're

20
00:00:48,370 --> 00:00:50,130
working with here itself isn't too

21
00:00:50,130 --> 00:00:52,150
important. Just pay attention to the

22
00:00:52,150 --> 00:00:54,900
versions in the next few exercises. I'll

23
00:00:54,900 --> 00:00:56,970
say yes again to the prompt about the PS

24
00:00:56,970 --> 00:01:00,180
Gallery not being trusted. And actually,

25
00:01:00,180 --> 00:01:01,980
while I remember, let me just run

26
00:01:01,980 --> 00:01:04,310
Set‑PSRepository to set the gallery to a

27
00:01:04,310 --> 00:01:06,230
trusted repo, so we stopped getting that

28
00:01:06,230 --> 00:01:09,170
prompt. I can confirm that the posh‑ssh

29
00:01:09,170 --> 00:01:11,220
module has been installed by running

30
00:01:11,220 --> 00:01:14,940
Get‑Module posh‑ssh ‑ListAvailable. And

31
00:01:14,940 --> 00:01:17,700
yep, all good. The command we need to use

32
00:01:17,700 --> 00:01:20,140
to update a module, shockingly, is named

33
00:01:20,140 --> 00:01:22,890
Update‑Module. As per the other commands,

34
00:01:22,890 --> 00:01:24,530
let's quickly check out the help for

35
00:01:24,530 --> 00:01:26,750
Update‑Module. And this command actually

36
00:01:26,750 --> 00:01:29,460
doesn't have any required parameters. I'm

37
00:01:29,460 --> 00:01:31,270
not going to do this, but if you run

38
00:01:31,270 --> 00:01:33,790
Update‑Module with no parameters, it will

39
00:01:33,790 --> 00:01:35,830
attempt to update all modules on this

40
00:01:35,830 --> 00:01:38,040
computer that have been installed via the

41
00:01:38,040 --> 00:01:40,740
PackageManagement Framework. Let's run

42
00:01:40,740 --> 00:01:43,630
Update‑Module for the posh‑ssh module, but

43
00:01:43,630 --> 00:01:45,510
let's use the RequiredVersion parameter

44
00:01:45,510 --> 00:01:48,080
again to specifically update to version

45
00:01:48,080 --> 00:01:51,260
2.1. I'll go back to check on that by

46
00:01:51,260 --> 00:01:53,660
running Get‑Module, and this is another

47
00:01:53,660 --> 00:01:55,390
important thing. I want you to be aware

48
00:01:55,390 --> 00:01:58,890
of. Updating a module does not remove the

49
00:01:58,890 --> 00:02:01,560
old version of that module. You need to

50
00:02:01,560 --> 00:02:03,880
explicitly uninstall the old version of a

51
00:02:03,880 --> 00:02:06,090
module using another command that we'll

52
00:02:06,090 --> 00:02:08,460
look at in the next clip. I'm going to say

53
00:02:08,460 --> 00:02:10,120
that again because it trips a lot of

54
00:02:10,120 --> 00:02:13,560
people up. Updating a module does not

55
00:02:13,560 --> 00:02:16,740
remove the old version of that module.

56
00:02:16,740 --> 00:02:19,500
Finally, if I do one last Update‑Module of

57
00:02:19,500 --> 00:02:22,290
posh‑ssh, but this time I won't specify a

58
00:02:22,290 --> 00:02:24,550
version, PowerShell will go and get the

59
00:02:24,550 --> 00:02:27,150
latest version of that module for me. If

60
00:02:27,150 --> 00:02:29,630
we check out Get‑Module for posh‑ssh

61
00:02:29,630 --> 00:02:32,070
again, we'll now see. 3 versions are

62
00:02:32,070 --> 00:02:35,100
installed, and version 2.2 is the latest

63
00:02:35,100 --> 00:02:36,640
version that was available on the

64
00:02:36,640 --> 00:02:40,190
PowerShell Gallery. If I run Import‑Module

65
00:02:40,190 --> 00:02:43,770
posh‑ssh and use the verbose parameter and

66
00:02:43,770 --> 00:02:46,300
scroll back up to the top, you'll see here

67
00:02:46,300 --> 00:02:47,810
that even though several versions are

68
00:02:47,810 --> 00:02:50,170
installed on my machine, it is loading the

69
00:02:50,170 --> 00:02:53,130
latest version of 2.2 by default into my

70
00:02:53,130 --> 00:02:55,450
session. To wrap up here with

71
00:02:55,450 --> 00:02:57,890
Update‑Module, there's another behavior I

72
00:02:57,890 --> 00:03:00,130
want you to be aware of, and again, this

73
00:03:00,130 --> 00:03:03,180
is important. Update‑Module will only

74
00:03:03,180 --> 00:03:05,330
update PowerShell modules that have been

75
00:03:05,330 --> 00:03:08,070
installed with the PowerShell GET command

76
00:03:08,070 --> 00:03:10,940
Install Module. Remember that all of this

77
00:03:10,940 --> 00:03:12,850
is built on top of that PackageManagement

78
00:03:12,850 --> 00:03:15,540
Framework, right? So if a module wasn't

79
00:03:15,540 --> 00:03:18,050
installed using that framework, it can't

80
00:03:18,050 --> 00:03:20,740
be updated by using that framework.

81
00:03:20,740 --> 00:03:22,250
There's a command that's a part of

82
00:03:22,250 --> 00:03:25,460
PowerShell GET named Get‑InstalledModule,

83
00:03:25,460 --> 00:03:27,390
which shows all modules that are installed

84
00:03:27,390 --> 00:03:30,360
on a computer using PowerShell GET. I'm

85
00:03:30,360 --> 00:03:32,550
going to run that inside of parentheses

86
00:03:32,550 --> 00:03:34,430
and then look at the count property to get

87
00:03:34,430 --> 00:03:36,270
the total number of installed modules,

88
00:03:36,270 --> 00:03:38,780
which is two. That would be the two

89
00:03:38,780 --> 00:03:41,440
modules we just installed, PS Slack and

90
00:03:41,440 --> 00:03:45,350
posh‑ssh. However, if I do the same thing,

91
00:03:45,350 --> 00:03:48,030
but run Get‑Module ‑ListAvailable, there

92
00:03:48,030 --> 00:03:50,490
are 78 PowerShell modules that exist on

93
00:03:50,490 --> 00:03:53,150
this computer. It just so happens that

94
00:03:53,150 --> 00:03:55,070
only two of them have been installed with

95
00:03:55,070 --> 00:03:57,550
the PackageManagement Framework. If I

96
00:03:57,550 --> 00:03:59,650
attempted to update a module that hasn't

97
00:03:59,650 --> 00:04:01,610
been installed using the PackageManagement

98
00:04:01,610 --> 00:04:04,730
Framework, such as the SmbShare module, it

99
00:04:04,730 --> 00:04:06,540
will helpfully tell us that it wasn't

100
00:04:06,540 --> 00:04:08,330
installed using the Install‑Module

101
00:04:08,330 --> 00:04:11,370
command, so it cannot be updated. If you

102
00:04:11,370 --> 00:04:13,320
wanted to be able to update this module,

103
00:04:13,320 --> 00:04:14,940
you'd first need to remove it from this

104
00:04:14,940 --> 00:04:17,140
system and then install it by using

105
00:04:17,140 --> 00:04:22,000
Install‑Module, so it becomes managed by the PackageManagement Framework.

