Uninstall Module - PowerShell


Overview

The Uninstall-Module cmdlet removes a PowerShell module and its dependent modules from the computer. Modules are reusable, self-contained units of functionality that can be imported into a PowerShell session. Uninstalling a module removes its associated files, registry entries, and any other resources it may have created.

Syntax

Uninstall-Module [-Name] <ModuleName> [[-RequiredVersion] <Version>] [-Scope <Scope>] [-Verbose] [-Force] [-Confirm] [<CommonParameters>]

Options/Flags

  • -Name: Specifies the name of the module to be uninstalled.
  • -RequiredVersion: Uninstalls the specified version of the module.
  • -Scope: Specifies the scope of the uninstallation. Valid values are:
    • CurrentUser: Uninstalls the module for the current user only.
    • AllUsers: Uninstalls the module for all users on the computer.
  • -Verbose: Outputs detailed information about the uninstallation process.
  • -Force: Forces the uninstallation even if the module is in use.
  • -Confirm: Prompts the user to confirm the uninstallation.

Examples

Example 1: Uninstalling a specific module

Uninstall-Module PowerShellGet

Example 2: Uninstalling a specific version of a module

Uninstall-Module -Name PowerShellGet -RequiredVersion 2.2.3

Example 3: Uninstalling a module for all users

Uninstall-Module -Name Chocolatey -Scope AllUsers

Example 4: Uninstalling a module with verbose output

Uninstall-Module -Name Azure -Verbose

Common Issues

Error: The module is in use

This error occurs when you attempt to uninstall a module that is currently being used by another process. To resolve this issue, close any applications using the module and then run the uninstall command again.

Error: The module cannot be found

This error indicates that the specified module is not installed on the computer. Verify that you have spelled the module name correctly and that it is installed before attempting to uninstall it.

Integration

Uninstall-Module can be integrated with other PowerShell commands to perform complex tasks. For example, you can use the following command to uninstall all modules installed for the current user:

Get-Module | Where-Object {$_.Scope -eq 'CurrentUser'} | Uninstall-Module