Skip to content

Instantly share code, notes, and snippets.

@rdronov
Last active December 21, 2018 04:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdronov/eb654f151ac640fc386d6237f9ecd015 to your computer and use it in GitHub Desktop.
Save rdronov/eb654f151ac640fc386d6237f9ecd015 to your computer and use it in GitHub Desktop.
# File name: Remove-OldPowerCLI.ps1
# Description: This script removes the old versions of VMware.PowerCLI and its dependencies
#
# 21/12/2018 - Version 1.0
# - Initial Release (based on https://windowsserver.uservoice.com/forums/301869-powershell/suggestions/14934876-update-module-needs-flag-to-remove-previous-versio)
#
# Author: Roman Dronov (c)
$modules = @((Get-Module -ListAvailable | ? {$_.Name -like "VMware*"}).Name | Get-Unique)
foreach ($module in $modules){
$latest = Get-InstalledModule -Name $module
Get-InstalledModule -Name $module -AllVersions | ? {$_.Version -ne $latest.Version} | Uninstall-Module -Force -Verbose
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment