A while ago I wrote a script that report all the previous versions of PowerShell modules that have been installed.
https://blog.ciaops.com/2025/03/28/report-installed-powershell-module-versions/
I’ve now done a script that will allow yoru to delete all these previous versions while retaining the current version. You’ll find that script here:
https://github.com/directorcia/Office365/blob/master/psmodules-del.ps1
# Example usage:
# Remove-OldPSModules # Process all modules without confirmation
# Remove-OldPSModules -SummaryOnly # Only show summary info, minimize verbose output
# Remove-OldPSModules -ModuleNames “Microsoft.Graph”, “Az” # Process specific modules
# Remove-OldPSModules -ConfirmUninstall # Ask before each removal
# Remove-OldPSModules -WhatIf # Simulation mode, no actual changes
# Remove-OldPSModules -ModuleNames “Az” -ConfirmUninstall -WhatIf # Combine parameters as needed
You can modify the execution part of the script at the bottom to suit your needs.
One thought on “Script to delete old installed PowerShell module versions”