When you're finished with a module, either
temporarily in this PowerShell session or
more permanently, there are a couple of
commands we can use to remove a module and
also to completely uninstall the module. I
want to ensure that you're aware of the
difference between Remove‑Module and
Uninstall‑Module. Remove‑Module will
remove the module from the current
PowerShell session. It's basically the
opposite of Import‑Module. Remove‑Module
does not remove the module from your
computer. To do that, you need to use
Uninstall‑Module. Let's run Get‑Module to
see which modules are loaded into this
session, and at the moment, we'll see
we've still got posh‑ssh from the previous
clip. If I run Remove‑Module posh‑ssh and
then run Get‑Module again, you'll notice
it is now no longer listed as a loaded
module in this session. But if I run
Get‑Module posh‑ssh ‑ListAvailable, you
can see that it's still found on my
machine, and if I needed to, I could go
ahead and import it again, either manually
or by using auto‑loading. Should we want
to fully uninstall it from this machine,
we need to use Uninstall‑Module. Let's
check out the help for that. This one is a
pretty straightforward command with
options for specifying which version we
want to uninstall. But also note that the
only mandatory parameter is the Name
parameter, which is the name of the module
we want to uninstall. Let's give it a go
with Uninstall‑Module posh‑ssh. And I'm
actually pretty sure this is going to
error out. Yep, there we go. I have a
feeling that this might be some sort of
bug in PowerShell 7, as I haven't
experienced this in earlier versions, but
it seems to think that the Posh‑SSH module
is still in use, even though we've removed
it from this session. I wanted to leave
this in the video so that you're aware of
it. And maybe by the time you're watching
this video, if you're following along,
hopefully it's fixed. All I need to do
here is close PowerShell and then reopen a
new session. Again, if I run
Uninstall‑Module posh‑ssh, this time it
goes through successfully. So now if I run
get‑module posh‑ssh ‑ListAvailable, do you
think we'll get any results or not? We've
just uninstalled it, right? So Get‑Module
shouldn't be able to find this module on
our computer. Ah, we have still got a few
results there. With Uninstall‑Module, you
need to be aware that by default, it will
only remove the latest version of the
module. If you happen to have multiple
versions of a module installed on your
machine and you want to remove them all,
then run Uninstall‑Module, and then use
the AllVersions parameter. This time, if
we use get‑module to check for anything on
our machine, we'll get zero results. And
we can now be certain that the Posh‑SSH module has been fully uninstalled.