Remove Module - PowerShell


Overview

Remove-Module unloads and removes a PowerShell module from the current PowerShell session. This allows you to remove unwanted or outdated modules.

Syntax

Remove-Module [-Name] <string[]> [-Force] [-PassThru] [-WhatIf] [-Confirm] [<CommonParameters>]

Options/Flags

| Parameter | Description | Default |
|—|—|—|
| -Name | Specifies the name of the module to remove. | |
| -Force | Suppresses confirmation prompts when removing modules. | False |
| -PassThru | Returns the removed module as an object. | False |
| -WhatIf | Simulates the command without actually making changes. | False |
| -Confirm | Prompts for confirmation before removing modules. | False |

Examples

Simple Removal

Remove-Module PowerShellGet

Forcing Removal without Confirmation

Remove-Module -Name Pester -Force

Removing Multiple Modules Simultaneously

Remove-Module -Name (Get-Module -ListAvailable)

Common Issues

  • Module Not Found: Ensure that the module name is spelled correctly.
  • Module In Use: Close any open PowerShell sessions or processes that may be using the module.

Integration

Resetting the Session

Combine with Import-Module to reset the PowerShell session with a clean module load state:

Remove-Module -Name *
Import-Module -Name *
  • Get-Module
  • Import-Module