• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
OpenTechTips

OpenTechTips

Practical IT Guides, Expert Tips, and Real-World Solutions

MENUMENU
  • HOME
  • ALL TOPICS
    • Exchange
    • InfoSec
    • Linux
    • Networking
    • Scripting
      • PowerShell
    • SSL
    • Tools
    • Virtualization
    • Web
    • Windows
  • ABOUT
  • SUBSCRIBE
Home ยป How to Delete Old PowerShell Modules

How to Delete Old PowerShell Modules

September 13, 2025 - by Zsolt Agoston - last edited on July 27, 2026

To delete old PowerShell modules, identify modules with multiple installed versions and uninstall every version except the newest. The function below automates that cleanup for modules installed through PowerShellGet.

Close other PowerShell sessions and keep any older version required by production scripts or compatibility testing.

Remove old module versions

Function Remove-OldModules {
  $latest = Get-InstalledModule
 
  Foreach ($module in $latest) { 
    $AllVersionsOfModule = Get-InstalledModule -Name $module.Name -AllVersions
	
	If ($AllVersionsOfModule.count -gt 1) {
		Write-Host -f yellow "[-] Uninstalling old versions of $($module.Name) [latest is $( $module.Version)]" -Verbose
		$AllVersionsOfModule | Where-Object {$_.Version -ne $module.Version} | Uninstall-Module
	}
  }
}

Preview installed versions first

Get-InstalledModule -AllVersions |
    Sort-Object Name, Version |
    Select-Object Name, Version, InstalledLocation

The function keeps the latest version and sends older versions to Uninstall-Module. A loaded module, a dependent module, or a module copied manually can prevent removal. Microsoft's Uninstall-Module documentation explains these restrictions.

Update and test the latest releases before cleanup using the PowerShell module update command.

How to delete old PowerShell modules safely

PowerShell can keep several versions of the same module side by side. This is useful for compatibility, but obsolete versions consume disk space and can make troubleshooting harder when different sessions load different releases. Before deleting anything, identify which version your scripts import and test the newest release in a non-production session.

Check module scope and installation path

Modules installed with -Scope CurrentUser normally live under the current profile, while all-user installations require administrative rights. The preview command shows InstalledLocation, allowing you to confirm both the version and scope. Do not manually remove folders from PSModulePath unless the module was originally copied there manually and its dependencies are understood.

Verify the cleanup

After the function finishes, run Get-InstalledModule -AllVersions again. Each processed module should retain its latest installed version. Open a new PowerShell session, import the modules used by your scripts, and run a basic functional test. If an older version is still present, check whether it is loaded, required by another module, installed under another user scope, or protected by file permissions.

Deleting old PowerShell modules does not update the remaining release. Use Update-Module first when you need a newer version, validate it, and only then remove superseded copies. Keeping a tested rollback package is sensible for critical automation.

Reader Interactions

Comments Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Tools

Secondary Sidebar

CONTENTS

  • Remove old module versions
  • Preview installed versions first
  • How to delete old PowerShell modules safely
  • Check module scope and installation path
  • Verify the cleanup

  • Terms of Use
  • Disclaimer
  • Privacy Policy
Manage your privacy
We use technologies like cookies to store and/or access device information. We do this to improve browsing experience and to show (non-) personalized ads. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
  • Manage options
  • Manage services
  • Manage {vendor_count} vendors
  • Read more about these purposes
Manage options
  • {title}
  • {title}
  • {title}
Manage your privacy
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
  • Manage options
  • Manage services
  • Manage {vendor_count} vendors
  • Read more about these purposes
Manage options
  • {title}
  • {title}
  • {title}