Windows OS Hub
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server 2025
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
    • Proxmox
  • PowerShell
  • Linux
  • Home
  • About

Windows OS Hub

  • Windows
    • Windows 11
    • Windows 10
    • Windows Server 2025
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
    • Proxmox
  • PowerShell
  • Linux

 Windows OS Hub / PowerShell / How to Remove Old (Unused) PowerShell Modules

January 12, 2026

How to Remove Old (Unused) PowerShell Modules

This article explains how to safely remove a PowerShell module installed on a Windows computer. This may be necessary in order to uninstall old or unused modules, resolve PowerShell slow startup issues, or fix module conflicts.

Use this command to list third-party PowerShell modules installed on a computer via registered repositories.

Get-InstalledModule

Get-InstalledModule - list the installed third-party PowerShell modules

This command lists third-party PowerShell modules installed and registered via the Install-Module cmdlet. In my case, all the PS modules are installed via the PSGallery repository.

To remove an installed module, specify its name in the Uninstall-Module command. For example:

Uninstall-Module -Name PSWindowsUpdate

A computer may have more than one version of the module installed. Therefore, this cmdlet will either remove the most recent version of the module or will fail if multiple versions are found. The available versions of the module can be displayed as follows:

Get-Module pswindowsupdate -ListAvailable

Get-Module -ListAvailable - list the module verions

To uninstall a specific module version

Uninstall-Module -Name PSWindowsUpdate -RequiredVersion 2.2.1.4 -Verbose

Remove all versions of a specific module except the latest one.

$moduleName = "PSWindowsUpdate"
$versions = Get-InstalledModule -Name $moduleName -AllVersions | Sort-Object Version -Descending
$versions | Select-Object -Skip 1 | ForEach-Object { Uninstall-Module -Name $moduleName -RequiredVersion $_.Version -Force }

Remove all module versions:

Uninstall-Module -Name PSWindowsUpdate -AllVersions

The Invoke-Command cmdlet can be used to remove the PowerShell module on a remote computer:

Invoke-Command -ComputerName mun-dc01 -ScriptBlock {Uninstall-Module PSWindowsUpdate -RequiredVersion 2.2.1.2 -Force -Verbose}

When uninstalling a module, an error may appear stating that the module is in use.

WARNING: The version '2.2.1.4' of module 'PSWindowsUpdate' is currently in use. Retry the operation after closing the applications.
PackageManagement\Uninstall-Package : Module 'PSWindowsUpdate' is in currently in use or you don't have the required permissions.

Uninstall-Module error - module is currently in use

To remove such a module, first close the PowerShell session in which it was loaded (imported). List the PS modules loaded in the current session:

Get-Module

To unload a module from memory without closing the current PS console, run the following command:

Remove-Module -Name PSWindowsUpdate

Remove-Module - unload specific powershell module from a session

Try removing the module again after this (in some cases, you need to add the -Force option to force the module removal, but be careful, as this can break the dependencies of other modules):

Uninstall-Module -Name PSWindowsUpdate -Force

If the module that you want to uninstall loads automatically when you open a PowerShell session, you can bypass this by launching the PowerShell console without loading your PS1 profile files:

Powershell.exe -NoProfile -Command "Uninstall-Module ImportExcel"

The complete list of all the PowerShell modules available on a computer (including those installed through the repository and those installed manually) can be displayed as follows:

Get-Module -ListAvailable|select name,version,path

Get-Module -ListAvailable - list all modules including build-in and manually installed

The Path column shows where the module files are located. In Windows PowerShell, you can use (import) modules that have been installed (copied) to the following directories:

C:\Users\%username%\Documents\WindowsPowerShell\Modules
C:\Program Files\WindowsPowerShell\Modules
C:\Windows\system32\WindowsPowerShell\v1.0\Modules

You can find this list of paths in the environment variable $env:PSModulePath:

$env:PSModulePath in Windows PowerShell 5.1

In PowerShell Core 7.x, the $env:PSModulePath variable includes the following additional paths:

C:\program files\windowsapps\microsoft.powershell_7.5.2.0_x64__8wekyb3d8bbwe\Modules
C:\Program Files\PowerShell\Modules
C:\program files\powershell\7\Modules

$env:PSModulePath paths in PowerShell Core 7.x

Residual files may remain in the module directory after uninstallation. These files must be manually removed. This PS script, for example, will uninstall a module and clear the contents of its folder if the folder is not empty.

$Module = Get-Module ImportExcel -ListAvailable
Uninstall-Module $Module.Name -verbose
Remove-Item $Module.ModuleBase -Recurse -Force

0 comment
1
Facebook Twitter Google + Pinterest
PowerShellQuestions and Answers
previous post
Windows Setup Could Not Display the Images Available for Installation

Related Reading

Uninstalling Windows Updates via CMD/PowerShell

April 18, 2025

How to Hide (Block) a Specific Windows Update

March 3, 2025

How to Write Logs to the Windows Event...

March 11, 2025

Run Elevated Commands with Sudo on Windows 11

August 21, 2025

How to Configure Windows Firewall Logging and Analyze...

February 17, 2025

Windows: How to Turn Off Monitor with Command...

February 17, 2025

How to Pause (Delay) Update Installation on Windows...

April 11, 2025

How to Find AD Users with Blank Passwords...

August 21, 2025

Leave a Comment Cancel Reply

join us telegram channel https://t.me/woshub
Join WindowsHub Telegram channel to get the latest updates!

Recent Posts

  • How to Move (Migrate) Existing Windows Shares to a New File Server

    December 24, 2025
  • Using KDC (Kerberos) Proxy in AD for Remote Access

    December 23, 2025
  • Windows: Create (Install) a Service Manually

    December 16, 2025
  • Windows: Auto Switch to Strongest Wi-Fi Network

    December 10, 2025
  • How to Enable or Disable VBScript in Windows after Deprecation

    December 10, 2025
  • Start Menu Not Working (Unresponsive) on Windows Server RDS

    November 27, 2025
  • AppLocker: Configure Application Restriction Policies in Windows

    November 19, 2025
  • Enable/Disable Random Hardware (MAC) Address for Wi-Fi on Windows

    November 14, 2025
  • Automate Software and Settings Deployment with WinGet Configure (DSC)

    November 13, 2025
  • SMB over QUIC: Mount File Share over Internet without VPN on Windows Server 2025

    November 4, 2025

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Automate Software and Settings Deployment with WinGet Configure (DSC)
  • Run Elevated Commands with Sudo on Windows 11
  • Fix: Slow Startup of PowerShell Console and Scripts
  • How to Pause (Delay) Update Installation on Windows 11 and 10
  • Enable/Disable Random Hardware (MAC) Address for Wi-Fi on Windows
  • How to Write Logs to the Windows Event Viewer from PowerShell/CMD
  • Allowing Ping (ICMP Echo) Responses in Windows Firewall
Footer Logo

@2014 - 2024 - Windows OS Hub. All about operating systems for sysadmins


Back To Top