Uninstall the Azure PowerShell module

This article tells you how to uninstall an older version of Azure PowerShell, or completely remove it from your system. If you've decided to completely uninstall the Azure PowerShell, give us some feedback through the Send-Feedback cmdlet. If you encounter a bug, we'd appreciate it if you file a GitHub issue.

Uninstall from PowerShell

If you installed Azure PowerShell using PowerShellGet, you can use the Uninstall-Module cmdlet. However, Uninstall-Module only uninstalls one module. To remove Azure PowerShell completely, you must uninstall each module individually. Uninstallation can be complicated if you have more than one version of Azure PowerShell installed.

To check which versions of Azure PowerShell you currently have installed, run the following command:

Get-InstalledModule -Name AzureRM -AllVersions
Version              Name                                Repository           Description
-------              ----                                ----------           -----------
6.11.0               AzureRM                             PSGallery            Azure Resource Manager Module
6.13.1               AzureRM                             PSGallery            Azure Resource Manager Module

The following script queries the PowerShell Gallery to get a list of dependent submodules. Then, the script uninstalls the correct version of each submodule. You will need to have administrator access to run this script in a scope other than Process or CurrentUser.

function Uninstall-AllModules {
  param(
    [Parameter(Mandatory=$true)]
    [string]$TargetModule,

    [Parameter(Mandatory=$true)]
    [string]$Version,

    [switch]$Force,

    [switch]$WhatIf
  )
  
  $AllModules = @()
  
  'Creating list of dependencies...'
  $target = Find-Module $TargetModule -RequiredVersion $version
  $target.Dependencies | ForEach-Object {
    if ($_.requiredVersion) {
      $AllModules += New-Object -TypeName psobject -Property @{name=$_.name; version=$_.requiredVersion}
    }
    else { # Assume minimum version
      # Minimum version actually reports the installed dependency
      # which is used, not the actual "minimum dependency." Check to
      # see if the requested version was installed as a dependency earlier.
      $candidate = Get-InstalledModule $_.name -RequiredVersion $version
      if ($candidate) {
        $AllModules += New-Object -TypeName psobject -Property @{name=$_.name; version=$version}
      }
      else {
        Write-Warning ("Could not find uninstall candidate for {0}:{1} - module may require manual uninstall" -f $_.name,$version)
      }
    }
  }
  $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 -WhatIf:$WhatIf
    } catch {
      Write-Host ("`t" + $_.Exception.Message)
    }
  }
}

To use this function, copy and paste the code into your PowerShell session. The following example shows how to run the function to remove an older version of Azure PowerShell.

Uninstall-AllModules -TargetModule AzureRM -Version 4.4.1 -Force

As the script runs, it will display the name and version of each submodule that is being uninstalled. To run the script to only see what would be deleted, without removing it, use the -WhatIf option.

Creating list of dependencies...
Uninstalling AzureRM.Profile version 3.4.1
Uninstalling Azure.Storage version 3.4.1
Uninstalling AzureRM.AnalysisServices version 0.4.7
Uninstalling Azure.AnalysisServices version 0.4.7
...

Run this command for every version of Azure PowerShell that you want to uninstall. For convenience, the following script will uninstall all versions of AzureRM except for the latest.

$versions = (get-installedmodule AzureRM -AllVersions | Select-Object Version)
$versions[1..($versions.Length-1)]  | foreach { Uninstall-AllModules -TargetModule AzureRM -Version ($_.Version) -Force }

Uninstall MSI

If you installed Azure PowerShell using the MSI package, you must uninstall through the Windows system rather than PowerShell.

Platform Instructions
Windows 10 Start > Settings > Apps
Windows 7
Windows 8
Start > Control Panel > Programs > Uninstall a program

Once on this screen you should see "Azure PowerShell" in the program listing, and can uninstall from there.