Skip to content

Instantly share code, notes, and snippets.

@Froosh
Last active December 6, 2023 00:46
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 Froosh/80bf931d1fe851d0fb2a8d980fd3b704 to your computer and use it in GitHub Desktop.
Save Froosh/80bf931d1fe851d0fb2a8d980fd3b704 to your computer and use it in GitHub Desktop.
Remove old modules, useful for after a few Az or Microsoft.Graph metamodule upgrades
Get-InstalledPSResource -Scope CurrentUser |
Group-Object -Property Name |
ForEach-Object -Process {
$VersionsToRemove = $PSItem.Group | Sort-Object -Property Version -Descending | Select-Object -Skip 1
foreach ($Version in $VersionsToRemove) {
Uninstall-PSResource -Verbose -Name $Version.Name -Version $Version.Version -SkipDependencyCheck
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment