From 2d633e9d9d31c045fa312b1385ac7aa0f7478ba9 Mon Sep 17 00:00:00 2001 From: msJinLei Date: Fri, 16 Oct 2020 02:43:51 +0800 Subject: [PATCH] Fix Az.Tools.Installer issues 1.Fix issue https://github.com/Azure/azure-powershell/issues/13167 2.Fix issue https://github.com/Azure/azure-powershell/issues/13174 --- tools/Az.Tools.Installer/exports/Install-AzModule.ps1 | 11 +++++++++-- .../internal/Get-AzModuleUpdateList.ps1 | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/tools/Az.Tools.Installer/exports/Install-AzModule.ps1 b/tools/Az.Tools.Installer/exports/Install-AzModule.ps1 index fd32a49563c6..bc33ab7fdb70 100644 --- a/tools/Az.Tools.Installer/exports/Install-AzModule.ps1 +++ b/tools/Az.Tools.Installer/exports/Install-AzModule.ps1 @@ -236,8 +236,15 @@ function Install-AzModule { } if ($RemoveAzureRm -and ($PSCmdlet.ShouldProcess('Remove AzureRm modules', 'AzureRm modules', 'Remove'))) { - Uninstall-Module -Name 'AzureRm*' -AllVersion -ErrorAction SilentlyContinue - Uninstall-Module -Name 'Azure.*' -AllVersion -ErrorAction SilentlyContinue + try { + $azureModuleNames = (Get-InstalledModule -Name Azure* -ErrorAction Stop).Name | Where-Object {$_ -match "Azure(\.[a-zA-Z0-9]+)?$" -or $_ -match "AzureRM(\.[a-zA-Z0-9]+)?$"} + foreach($azureModuleName in $azureModuleNames) { + Uninstall-Module -Name $azureModuleName -AllVersion -ErrorAction SilentlyContinue + } + } + catch { + Write-Warning $_ + } } #install Az.Accounts first diff --git a/tools/Az.Tools.Installer/internal/Get-AzModuleUpdateList.ps1 b/tools/Az.Tools.Installer/internal/Get-AzModuleUpdateList.ps1 index ff7611866e50..c1c53aa9ce01 100644 --- a/tools/Az.Tools.Installer/internal/Get-AzModuleUpdateList.ps1 +++ b/tools/Az.Tools.Installer/internal/Get-AzModuleUpdateList.ps1 @@ -47,7 +47,7 @@ function Get-AzModuleUpdateList { if ($installModules.Keys -gt 0) { foreach ($key in $installModules.Keys.Clone()) { - $installedModules = (PowerShellGet\Get-InstalledModule -Name $key -AllVersions).Where( { -not $_.AdditionalMetadata.IsPrerelease }) + $installedModules = (PowerShellGet\Get-InstalledModule -Name $key -AllVersions) | Where-Object { -not $_.AdditionalMetadata.IsPrerelease } foreach ($installed in $installedModules) { $installModules[$key] += [System.Tuple]::Create($installed.Version, $installed.Repository) }