From the course: Learning PowerShell Core

Install, uninstall and update modules - PowerShell Tutorial

From the course: Learning PowerShell Core

Start my 1-month free trial

Install, uninstall and update modules

So that's how you can get a listing of all the PowerShell modules. Let's say that I found one that I want to download and install. I'll use one called CallPass. Whenever I run Find-Module, you can see that there's CallPass Version 1.0.1 available, and I want to install that. To install it, I will just hit my Up Arrow here, bring back my history, and then I will use the Pipeline to pipe that module to Install-Module. Hit Enter, and then now you will see that it always brings up this untrusted repository. There are ways around that, but it's out of the scope of this course, however what this is doing is the PowerShellGet module has some security in it, that it trusts certain repository. If you use Install-Module without any other kind of parameters, just a module object, it will default to the PowerShell Gallery repository and by default that is not trusted. Whenever this comes up, you can hit Y for yes or A for all to make sure all of the prompts are confirmed. I will just hit A for now. Now the CallPass module should be installed. Check it out. We'll run "Get-Module -Name "callpass," and now you can see that the CallPass module is available and there are a few commands in it. We have downloaded and installed the module and it is available for us. Next up, let's see how we an uninstall a module. We've installed it. Now how do we uninstall it? You learned about the Remove-Module command. That command just removes it from the current session. It doesn't actually remove it from the file system. To remove a module, we can use the Uninstall-Module command. I'll Up Arrow here and find my module object, and I will pipe this to "Uninstall-Module" now. Hit Enter. Now the module should be uninstalled. Lets check and see what shows up here, and it's still showing up here. That shows up there because that didn't actually remove it from the current session. "Uninstall-Module" removes it from the file system. The module itself is still in memory. What we can do is we can remove that from memory using "Remove-Module -Name callpass" and now it should be removed form memory. Check it out. It's not here. Using the ListAvailable parameter that we know will pull module on the file system to see if it's there, and it's not there. It's officially gone. Next up, let's look at how we can update a module. Let's say that I'm going to update, I don't know, the PowerShell Get-Module. It's a random module that we chose here. Let's find out what version I currently have on my machine. It looks like 2.1.3. Now let's see what version is on the PowerShell Gallery... 2.2, so the later version is on the PowerShell Gallery. I want to update that to 2.2, so to do that, I would Up Arrow a few times here and then I will get my PowerShell module object returned. Then I will pipe this to Update-Module. It errored out. That's because the Update-Module command cannot update all modules. It can only update modules that are available from the PowerShell Gallery, so since PowerShellGet didn't come from the PowerShell Gallery, it's not able to update it. However, let's hit Up Arrow a few times and let's install that CallPass module that we've been working with. Notice now that I'm not using the Pipeline. I'm just using Install-Module, and then providing it the name so I don't have to use the pipeline. I'll hit A to confirm, and now it should be installed. Let's check and see by hitting Up Arrow a few times. It's not currently in the session. Let's check the file system... and it is there. Okay, once it's there, we can return it. We are returning the module object, and let's pipe that to Update-Module. Now you can see that we don't return an error. This didn't upgrade it because the version that's currently on my system is the same version in the PowerShell Gallery but this is how you would update modules. That's been a complete lifecycle from finding modules in the PowerShell Gallery, installing, uninstalling, and then updating them.

Contents