Disabling Modules with PowerShell ModuleManager
- Written by Brittney Ryn
- Last Updated: 09 October 2019
- Created: 01 July 2019
- Hits: 4725
Have you ever been frustrated with PowerShell for importing the wrong version of a module, but you don’t want to completely remove that version? In this article I will show you how the Disable module feature in PowerShell ModuleManager can eliminate this frustration, and I will also demonstrate the basic functionality of the Disable feature. But first, let’s review some PowerShell behavior.
PowerShell – Module Import Behavior
Beginning in Windows PowerShell 3.0, modules are imported automatically when any cmdlet or function in the module is used in a command. When importing a module into a session, PowerShell does not always import the latest version of a module. It searches for the specified module in the paths defined in the value of the environmental variable, PSModulePath. For example, when the first path in PSModulePath is $home\Documents\WindowsPowerShell\Modules and any version of the module is installed in that directory, PowerShell then searches for module files in the following order:
- Module Manifest files (.psd1)
- Script Module files (.psm1)
- Binary Module files (.dll)
The Import-Module cmdlet has parameters to help explicitly import modules—such as RequiredVersion, MinimumVersion, and MaximumVersion—but it will import the first module found that meets the specified criteria.
The PowerShell ModuleManager Disable feature moves a module from the path saved in the value of the PSModulePath environment variable ($env:PSModulePath). Disabling a module is not the same as uninstalling. Disabling specific versions of a module allows you to control which module PowerShell will load. Disabling a module moves it to a folder in ProgramData, and enabling moves it back to the previous location. If modules are no longer needed, they can simply be uninstalled.
If you are unsure if other modules are dependent on a particular module, disabling it is the easiest option because this avoids having to reinstall the module. If it is later determined that the module is needed, simply enable it.
To see Disabled modules in the main view, select the Disabled filter on the ribbon (Home > Filter):
There are two buttons in the Installed section on the ribbon (Home > Installed):
- Disable: Moves one version or all versions of a module, depending on if the parent node is selected or a version child node.
- Disable All Versions: Moves all versions of a module, regardless of what is selected.
These buttons act like toggles. When a module is disabled, the buttons are highlighted. When a module needs to be enabled—or moved back to its original location—clicking Disable or Disable All Versions moves the modules and the buttons will no longer be highlighted.
When a module is disabled, it will update to look like the following:
In PowerShell ModuleManager service release v1.1.2, the main view was updated to a tree layout where the versions installed are directly under the main module information. Each version is updated to reflect disabled, and when all versions are disabled the parent node will update to disabled.
When modules are disabled, they will also appear in the Disabled Modules panel:
Modules can be enabled or uninstalled from the Disabled Modules panel.