Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive
 

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.

Disable Modules

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):

PMG ribbonDisabledFilter

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.

PMG ribbonDisabled

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:

PMG TreelistDisabled

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:

PMG DisabledModulesPanelDark

Modules can be enabled or uninstalled from the Disabled Modules panel.

If you have questions about our products, please post in our support forum.
For licensed customers, use the forum associated with your product in our Product Support Forums for Registered Customers.
For users of trial versions, please post in our Former and Future Customers - Questions forum.
Copyright © 2024 SAPIEN Technologies, Inc.