Skip to content

Commit 2f832e2

Browse files
authored
Fix Az.Tools.Installer issues (#13236)
1.Fix issue #13167 2.Fix issue #13174
1 parent 445918f commit 2f832e2

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

tools/Az.Tools.Installer/exports/Install-AzModule.ps1

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,15 @@ function Install-AzModule {
236236
}
237237

238238
if ($RemoveAzureRm -and ($PSCmdlet.ShouldProcess('Remove AzureRm modules', 'AzureRm modules', 'Remove'))) {
239-
Uninstall-Module -Name 'AzureRm*' -AllVersion -ErrorAction SilentlyContinue
240-
Uninstall-Module -Name 'Azure.*' -AllVersion -ErrorAction SilentlyContinue
239+
try {
240+
$azureModuleNames = (Get-InstalledModule -Name Azure* -ErrorAction Stop).Name | Where-Object {$_ -match "Azure(\.[a-zA-Z0-9]+)?$" -or $_ -match "AzureRM(\.[a-zA-Z0-9]+)?$"}
241+
foreach($azureModuleName in $azureModuleNames) {
242+
Uninstall-Module -Name $azureModuleName -AllVersion -ErrorAction SilentlyContinue
243+
}
244+
}
245+
catch {
246+
Write-Warning $_
247+
}
241248
}
242249

243250
#install Az.Accounts first

tools/Az.Tools.Installer/internal/Get-AzModuleUpdateList.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function Get-AzModuleUpdateList {
4747

4848
if ($installModules.Keys -gt 0) {
4949
foreach ($key in $installModules.Keys.Clone()) {
50-
$installedModules = (PowerShellGet\Get-InstalledModule -Name $key -AllVersions).Where( { -not $_.AdditionalMetadata.IsPrerelease })
50+
$installedModules = (PowerShellGet\Get-InstalledModule -Name $key -AllVersions) | Where-Object { -not $_.AdditionalMetadata.IsPrerelease }
5151
foreach ($installed in $installedModules) {
5252
$installModules[$key] += [System.Tuple]::Create($installed.Version, $installed.Repository)
5353
}

0 commit comments

Comments
 (0)