To uninstall a PowerShell module, use the Uninstall-Module cmdlet, which removes a module that was installed from the PowerShell Gallery. You can also manually delete the module folder if the cmdlet fails, but the cmdlet is the safest and recommended method for most users.
Why You Might Need to Uninstall a Module
PowerShell modules are packages of cmdlets, functions, and scripts that extend the shell’s capabilities. You might want to uninstall one for several reasons: it’s outdated, it conflicts with another module, it’s no longer needed, or you’re troubleshooting a script error. Removing a module cleanly prevents leftover files from causing confusion or breaking other scripts that depend on a specific version.
How Uninstall-Module Works
The Uninstall-Module cmdlet is part of the PowerShellGet module, which is included with PowerShell 5.1 and later. It removes the module from the PSModulePath locations where it was installed. When you run it, PowerShell checks the module’s dependencies and prompts you to confirm if other modules rely on it. The cmdlet also removes the module’s entry from the installed modules list, so it no longer appears in Get-Module -ListAvailable.
Step-by-Step: Uninstall a Module with PowerShell
- Open PowerShell as an administrator (right-click and select “Run as administrator”).
- Check the exact module name and version:
Get-Module -ListAvailable | Where-Object {$_.Name -eq 'ModuleName'} - Run the uninstall command:
Uninstall-Module -Name ModuleName - If you have multiple versions, specify the version:
Uninstall-Module -Name ModuleName -RequiredVersion 2.0.1 - Confirm the removal:
Get-Module -ListAvailable | Where-Object {$_.Name -eq 'ModuleName'}should return nothing.
If the module is currently in use, you may need to close the session or run the command from a different PowerShell window.
Manual Uninstall: Deleting the Module Folder
If Uninstall-Module fails (e.g., the module was installed by copying files manually), you can delete the folder manually. First, find the module path:
Get-Module -ListAvailable -Name ModuleName | Select-Object -ExpandProperty Path
Then delete that folder using Remove-Item -Path "C:\Program Files\WindowsPowerShell\Modules\ModuleName" -Recurse -Force. Be careful: this removes all versions in that folder. If the module was installed per-user (under Documents\WindowsPowerShell\Modules), delete that path instead. Always verify you’re deleting the right folder—removing a system module can break PowerShell itself.
Common Problems and Fixes
- “Module not found” error: The module name might be case-sensitive or the module isn’t installed for the current user. Use
Get-Module -ListAvailableto see all installed modules. - Dependency warnings: If other modules depend on it, PowerShell will ask for confirmation. Use
-Forceto skip the prompt, but only if you’re sure nothing else needs it. - Permission denied: If the module is in a protected location (like
C:\Program Files), you must run PowerShell as administrator. - Module still appears after uninstall: Clear the module cache with
Remove-Item -Path $env:LOCALAPPDATA\Microsoft\Windows\PowerShell\PowerShellGet\ -Recurse -Force(this resets the PowerShellGet cache).
Uninstalling vs. Removing a Module from a Session
Don’t confuse uninstalling with removing a module from the current session. Remove-Module unloads a module from memory but leaves the files on disk. This is useful when you want to reload a module or free memory. Uninstalling, on the other hand, deletes the files permanently. If you only want to stop using a module temporarily, use Remove-Module.
Alternatives to Uninstalling
Sometimes you don’t need to uninstall—you can just update the module with Update-Module -Name ModuleName. If you want to prevent a module from loading automatically, you can change the PSModulePath environment variable to exclude its folder. Or, if you’re testing a script, you can use Import-Module -Name ModuleName -NoClobber to load a specific version without affecting the installed one.
Frequently Asked Questions
How do I uninstall a module that was installed with Install-Module?
Use Uninstall-Module -Name ModuleName. This is the standard method for modules from the PowerShell Gallery. If you installed it manually (e.g., by copying files), you’ll need to delete the folder.
Can I uninstall a module without admin rights?
Yes, if the module is installed in your user’s Documents\WindowsPowerShell\Modules folder. If it’s in C:\Program Files\WindowsPowerShell\Modules, you need admin rights to modify it.
What if Uninstall-Module says “Module not found”?
Check the exact name with Get-Module -ListAvailable. The name might be different from what you think (e.g., it might be a prefix). Also, ensure you’re running the command in the same PowerShell version where the module is installed (Windows PowerShell vs. PowerShell 7).
How do I uninstall all versions of a module?
By default, Uninstall-Module removes all versions. If you only want to remove a specific version, use -RequiredVersion. To remove all, just run the cmdlet without the version parameter.
Does uninstalling a module affect my scripts?
Yes, if a script requires that module, it will fail until you reinstall it. Check your scripts for Import-Module statements or module dependencies before uninstalling.
Can I undo an uninstall?
No, uninstalling permanently deletes the module files. You’ll need to reinstall it from the PowerShell Gallery or from your backup. Always export a list of installed modules before mass uninstalls.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Connect Phone to Controller for Cloud Gaming
- Python Search Highlighting: Snippets & Matches
- Secure Boot Battlefield 6 ASUS: Fix & Enable Guide
- Best Tech Websites to Follow for Pros & Beginners
- Second Wind Quest Walkthrough: Where Winds Meet6.00 min/km
- Enshrouded Weapon Upgrade Guide: How to Improve Gear5.00 min/km