Last active
April 28, 2020 14:09
-
-
Save SQLtattoo/cc0f29af4bf6cf6442acba0398000e23 to your computer and use it in GitHub Desktop.
Remove all versions of a PowerShell module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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