1
00:00:00,940 --> 00:00:03,020
When you're finished with a module, either

2
00:00:03,020 --> 00:00:05,510
temporarily in this PowerShell session or

3
00:00:05,510 --> 00:00:07,760
more permanently, there are a couple of

4
00:00:07,760 --> 00:00:10,400
commands we can use to remove a module and

5
00:00:10,400 --> 00:00:13,430
also to completely uninstall the module. I

6
00:00:13,430 --> 00:00:14,910
want to ensure that you're aware of the

7
00:00:14,910 --> 00:00:16,870
difference between Remove‑Module and

8
00:00:16,870 --> 00:00:19,690
Uninstall‑Module. Remove‑Module will

9
00:00:19,690 --> 00:00:21,280
remove the module from the current

10
00:00:21,280 --> 00:00:23,450
PowerShell session. It's basically the

11
00:00:23,450 --> 00:00:26,460
opposite of Import‑Module. Remove‑Module

12
00:00:26,460 --> 00:00:28,340
does not remove the module from your

13
00:00:28,340 --> 00:00:31,060
computer. To do that, you need to use

14
00:00:31,060 --> 00:00:34,550
Uninstall‑Module. Let's run Get‑Module to

15
00:00:34,550 --> 00:00:36,220
see which modules are loaded into this

16
00:00:36,220 --> 00:00:38,760
session, and at the moment, we'll see

17
00:00:38,760 --> 00:00:41,080
we've still got posh‑ssh from the previous

18
00:00:41,080 --> 00:00:45,210
clip. If I run Remove‑Module posh‑ssh and

19
00:00:45,210 --> 00:00:47,440
then run Get‑Module again, you'll notice

20
00:00:47,440 --> 00:00:49,610
it is now no longer listed as a loaded

21
00:00:49,610 --> 00:00:52,030
module in this session. But if I run

22
00:00:52,030 --> 00:00:55,260
Get‑Module posh‑ssh ‑ListAvailable, you

23
00:00:55,260 --> 00:00:56,720
can see that it's still found on my

24
00:00:56,720 --> 00:00:59,280
machine, and if I needed to, I could go

25
00:00:59,280 --> 00:01:01,680
ahead and import it again, either manually

26
00:01:01,680 --> 00:01:04,630
or by using auto‑loading. Should we want

27
00:01:04,630 --> 00:01:06,920
to fully uninstall it from this machine,

28
00:01:06,920 --> 00:01:09,490
we need to use Uninstall‑Module. Let's

29
00:01:09,490 --> 00:01:12,030
check out the help for that. This one is a

30
00:01:12,030 --> 00:01:13,610
pretty straightforward command with

31
00:01:13,610 --> 00:01:15,750
options for specifying which version we

32
00:01:15,750 --> 00:01:18,210
want to uninstall. But also note that the

33
00:01:18,210 --> 00:01:20,300
only mandatory parameter is the Name

34
00:01:20,300 --> 00:01:22,340
parameter, which is the name of the module

35
00:01:22,340 --> 00:01:25,080
we want to uninstall. Let's give it a go

36
00:01:25,080 --> 00:01:28,790
with Uninstall‑Module posh‑ssh. And I'm

37
00:01:28,790 --> 00:01:30,190
actually pretty sure this is going to

38
00:01:30,190 --> 00:01:33,910
error out. Yep, there we go. I have a

39
00:01:33,910 --> 00:01:35,400
feeling that this might be some sort of

40
00:01:35,400 --> 00:01:37,610
bug in PowerShell 7, as I haven't

41
00:01:37,610 --> 00:01:39,960
experienced this in earlier versions, but

42
00:01:39,960 --> 00:01:42,210
it seems to think that the Posh‑SSH module

43
00:01:42,210 --> 00:01:44,450
is still in use, even though we've removed

44
00:01:44,450 --> 00:01:46,520
it from this session. I wanted to leave

45
00:01:46,520 --> 00:01:48,420
this in the video so that you're aware of

46
00:01:48,420 --> 00:01:50,250
it. And maybe by the time you're watching

47
00:01:50,250 --> 00:01:52,160
this video, if you're following along,

48
00:01:52,160 --> 00:01:54,690
hopefully it's fixed. All I need to do

49
00:01:54,690 --> 00:01:57,460
here is close PowerShell and then reopen a

50
00:01:57,460 --> 00:02:00,200
new session. Again, if I run

51
00:02:00,200 --> 00:02:03,350
Uninstall‑Module posh‑ssh, this time it

52
00:02:03,350 --> 00:02:06,490
goes through successfully. So now if I run

53
00:02:06,490 --> 00:02:10,070
get‑module posh‑ssh ‑ListAvailable, do you

54
00:02:10,070 --> 00:02:12,710
think we'll get any results or not? We've

55
00:02:12,710 --> 00:02:14,980
just uninstalled it, right? So Get‑Module

56
00:02:14,980 --> 00:02:16,880
shouldn't be able to find this module on

57
00:02:16,880 --> 00:02:19,490
our computer. Ah, we have still got a few

58
00:02:19,490 --> 00:02:22,690
results there. With Uninstall‑Module, you

59
00:02:22,690 --> 00:02:24,920
need to be aware that by default, it will

60
00:02:24,920 --> 00:02:26,860
only remove the latest version of the

61
00:02:26,860 --> 00:02:29,310
module. If you happen to have multiple

62
00:02:29,310 --> 00:02:31,070
versions of a module installed on your

63
00:02:31,070 --> 00:02:33,370
machine and you want to remove them all,

64
00:02:33,370 --> 00:02:35,670
then run Uninstall‑Module, and then use

65
00:02:35,670 --> 00:02:38,620
the AllVersions parameter. This time, if

66
00:02:38,620 --> 00:02:40,600
we use get‑module to check for anything on

67
00:02:40,600 --> 00:02:42,980
our machine, we'll get zero results. And

68
00:02:42,980 --> 00:02:49,000
we can now be certain that the Posh‑SSH module has been fully uninstalled.

