Managing PowerShell Modules

PowerShell code is packaged as modules.

Note: I'm talking about packages for PowerShell itself opposed to packages for Windows. Windows packages might come from the Microsoft Store, Chocolatey, WinGet, MSIX or other sources.

Managing modules is confusing because the cmdlets were developed incrementally before Microsoft contemplated online repositories.

So, there is a historical set of cmdlets which were designed to manage local modules.

There is a set of cmdlets to manage repositories. For example, there are cmdlets to add or remove repositories. Repositories are places from which you can download modules.

And there is a set of cmdlets to manage modules downloaded from those repositories.

Each of these collections is technically an assembly. (But, Microsoft will often refer to them as modules.) If the cmdlet you're looking for does not exist in one assembly then you will have to look in the others.

I've never mastered managing modules in PowerShell.

My goal for this gemlog is to provide instructions for common tasks and to add new instructions over time.

List the Available Commands

A basic skill is to list the cmdlets available for managing modules.

If there is some issue that I don't address, you can use this to begin looking for a solution.

Use the example below to list the module cmdlets. Make sure to type or copy the leading ampersand &. Here, I include the output from my system.

& { Get-Command -Module Microsoft.PowerShell.Core -Noun Module ;  
Get-Command -Module PackageManagement ;  
Get-Command -Module PowerShellGet -Noun Module, PSRepository, InstalledModule ; 
} | Format-Table -AutoSize 

CommandType Name                     Version   Source
----------- ----                     -------   ------
Cmdlet      Get-Module      Microsoft.PowerShell.Core
Cmdlet      Import-Module   Microsoft.PowerShell.Core
Cmdlet      New-Module      Microsoft.PowerShell.Core
Cmdlet      Remove-Module   Microsoft.PowerShell.Core
Cmdlet      Find-Package             1.4.7     PackageManagement
Cmdlet      Find-PackageProvider     1.4.7     PackageManagement
Cmdlet      Get-Package              1.4.7     PackageManagement
Cmdlet      Get-PackageProvider      1.4.7     PackageManagement
Cmdlet      Get-PackageSource        1.4.7     PackageManagement
Cmdlet      Import-PackageProvider   1.4.7     PackageManagement
Cmdlet      Install-Package          1.4.7     PackageManagement
Cmdlet      Install-PackageProvider  1.4.7     PackageManagement
Cmdlet      Register-PackageSource   1.4.7     PackageManagement
Cmdlet      Save-Package             1.4.7     PackageManagement
Cmdlet      Set-PackageSource        1.4.7     PackageManagement
Cmdlet      Uninstall-Package        1.4.7     PackageManagement
Cmdlet      Unregister-PackageSource 1.4.7     PackageManagement
Function    Find-Module              2.2.5     PowerShellGet
Function    Get-InstalledModule      2.2.5     PowerShellGet
Function    Get-PSRepository         2.2.5     PowerShellGet
Function    Install-Module           2.2.5     PowerShellGet
Function    Publish-Module           2.2.5     PowerShellGet
Function    Register-PSRepository    2.2.5     PowerShellGet
Function    Save-Module              2.2.5     PowerShellGet
Function    Set-PSRepository         2.2.5     PowerShellGet
Function    Uninstall-Module         2.2.5     PowerShellGet
Function    Unregister-PSRepository  2.2.5     PowerShellGet
Function    Update-Module            2.2.5     PowerShellGet

Browse Cmdlets Online

You can browse the available cmdlets online.

Below, you can find the home page for each assembly.

Note that some of the cmdlets shown are not related to managing PowerShell modules. Some of the assemblies have multiple roles.

Microsoft.PowerShell.Core | Microsoft Docs

On this page, look for "*-Module" cmdlets where the asterisk * can stand for any PowerShell verb like Get (Get-Module) or Import (Import-Module).

PackageManagement | Microsoft Docs

All the cmdlets in PackageManagement are relevant.

PowerShellGet | Microsoft Docs

Look for "*-Module", "*-PSRepository", and "*-InstalledModule" cmdlets here.

List Downloaded Modules

If you want to list modules that you've installed from online repositories, use the Get-InstalledModule cmdlet:

Get-InstalledModule | Format-Table -AutoSize

Version Name                                 Repository Description
------- ----                                 ---------- -----------
7.8.0   ImportExcel                          PSGallery  PowerShell module to i…
0.7.2   Microsoft.PowerShell.ConsoleGuiTools PSGallery  Cross-platform Console…

Update Downloaded Modules

To update the modules you've installed, use Update-Module.

A progress bar will show while the cmdlet is working.

Modules that are updated will be output. If all modules are up-to-date then there is no output.



Uninstall Downloaded Module

If you've downloaded a module from a repository, Uninstall-Package appears to be the correct cmdlet to uninstall the module.

# List Installed Modules
Get-InstalledModule | Format-Table -AutoSize  

Version         Name                                 Repository Description
-------         ----                                 ---------- -----------
7.8.1           ImportExcel                          PSGallery  PowerShell mod…
1.1.0-Preview01 Microsoft.PowerShell.Crescendo       PSGallery  Module that im…
0.4.0           Microsoft.PowerShell.WhatsNew        PSGallery  The Get-WhatsN…
0.7.2           Microsoft.PowerShell.ConsoleGuiTools PSGallery  Cross-platform…

# Uninstall WhatsNew using the full assembly name. 
Uninstall-Package Microsoft.PowerShell.WhatsNew      

Name                           Version          Source           Summary
----                           -------          ------           -------
Microsoft.PowerShell.WhatsNew  0.4.0            https://www.pow… The Get-Whats…

# List Installed Modules
Get-InstalledModule | Format-Table -AutoSize  

Version         Name                                 Repository Description
-------         ----                                 ---------- -----------
7.8.1           ImportExcel                          PSGallery  PowerShell mod…
1.1.0-Preview01 Microsoft.PowerShell.Crescendo       PSGallery  Module that im…
0.7.2           Microsoft.PowerShell.ConsoleGuiTools PSGallery  Cross-platform…


See the "Browse Cmdlets Online" section above for more information.

Update-Module | Microsoft Docs

Get-InstalledModule | Microsoft Docs

Format-Table | Microsoft Docs

Chocolatey: The package manager for Windows

WinGet | GitHub

What is MSIX? | Microsoft Docs

GraphicalTools Module | GitHub

dfinke/ImportExcel: PowerShell module to import/export Excel spreadsheets, without Excel | GitHub

PowerShell Verbs | Microsoft Docs

Created: Thursday, September 8, 2022

Updated: Tuesday, December 6, 2022