Skip to content

Instantly share code, notes, and snippets.

@SQLtattoo
Last active April 28, 2020 14:09
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 SQLtattoo/cc0f29af4bf6cf6442acba0398000e23 to your computer and use it in GitHub Desktop.
Save SQLtattoo/cc0f29af4bf6cf6442acba0398000e23 to your computer and use it in GitHub Desktop.
Remove all versions of a PowerShell module
# Make sure you understand that by running code it REMOVES ALL
# the versions of the specific module in this example of the
# module Az. No error handling.
# TAKE EXTRA CAUTION IF RUNNING ON PRODUCTION ENVIRONMENT!
$versions = Get-InstalledModule Az.* | Select-Object -Property Name,Version
$countmods = Get-InstalledModule Az.* | Measure-Object
Write-Host "Modules found: " $versions
while($countmods.Count -gt 0)
{
$versions | foreach {
Uninstall-Module -Name $_.Name -MinimumVersion $_.Version -Force
Write-Host "Removed: " $_.Name $_.Version
}
$versions = Get-InstalledModule Az.* | Select-Object -Property Name,Version
$countmods = Get-InstalledModule Az.* | Measure-Object
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment