Created
October 28, 2018 22:35
-
-
Save MattCotterellNZ/68ab8f785733b4db5d543242665c14d0 to your computer and use it in GitHub Desktop.
AzureRM -> Az
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
# https://docs.microsoft.com/en-us/powershell/azure/uninstall-azurerm-ps | |
# List versions | |
Get-Module -Name AzureRM -List | select Name,Version | |
#Create helper function | |
function Uninstall-AllModules { | |
param( | |
[Parameter(Mandatory=$true)] | |
[string]$TargetModule, | |
[Parameter(Mandatory=$true)] | |
[string]$Version, | |
[switch]$Force | |
) | |
$AllModules = @() | |
'Creating list of dependencies...' | |
$target = Find-Module $TargetModule -RequiredVersion $version | |
$target.Dependencies | ForEach-Object { | |
$AllModules += New-Object -TypeName psobject -Property @{name=$_.name; version=$_.requiredversion} | |
} | |
$AllModules += New-Object -TypeName psobject -Property @{name=$TargetModule; version=$Version} | |
foreach ($module in $AllModules) { | |
Write-Host ('Uninstalling {0} version {1}' -f $module.name,$module.version) | |
try { | |
Uninstall-Module -Name $module.name -RequiredVersion $module.version -Force:$Force -ErrorAction Stop | |
} catch { | |
Write-Host ("`t" + $_.Exception.Message) | |
} | |
} | |
} | |
# Uninstall AzureRM versions (replace versions with ones shown from line 4 | |
Uninstall-AllModules -TargetModule AzureRM -Version 6.8.1 -Force | |
Uninstall-AllModules -TargetModule AzureRM -Version 5.7.0 -Force | |
# Install Az | |
Install-Module Az | |
# Enable AzureRM compatibility | |
Enable-AzureRmAlias -Scope CurrentUser |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment