Install and uninstall AZ module in Powershell for Azure

Install/Remove AZ module in Powershell for Azure

Following prerequisite done on window machine before install

  1. For install powershell be the latest version above 7.
  2. Check the dot net version min version Install .NET Framework 4.7.2 or later.
-- For Check version 4.7.2 or later, following command will return TRUE
(Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full").Release -ge 461808

Install AZ Module in Powershell

  1. Install Module for setup AZ command.
Install-Module -Name Az -AllowClobber -Force

OR 

Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force

Note:
AllowClobber: Overrides warning messages about installation conflicts about existing commands on a computer.
Force: allows for multiple versions to be installed. Its overwrite the version if already exists.

Check the version of AZ module already installed

Get-InstalledModule -Name Az -AllVersions | Select-object -Property Name, Version

OR
Get-InstalledModule Azure -AllVersions | Select-Object Name,Version,Path

Uninstall Az Module

Remove the Az PowerShell module completely, you must uninstall each module individually. Uninstall-Module only uninstalls the modules specified for the Name parameter.

  1. List of all the Az PowerShell module versions into variable.
Get-Module -Name Az -ListAvailable -OutVariable AzVersions

2. List of all the Az PowerShell modules that need to be uninstalled in addition to the Az module.

($AzVersions |
  ForEach-Object {
    Import-Clixml -Path (Join-Path -Path $_.ModuleBase -ChildPath PSGetModuleInfo.xml)
  }).Dependencies.Name | Sort-Object -Descending -Unique -OutVariable AzModules

3. Remove the Az modules from memory and then uninstall them.

$AzModules |
  ForEach-Object {
    Remove-Module -Name $_ -ErrorAction SilentlyContinue
    Write-Output "Attempting to uninstall module: $_"
    Uninstall-Module -Name $_ -AllVersions
  }

4. Finally, remove the Az PowerShell module.

Remove-Module -Name Az -ErrorAction SilentlyContinue
Uninstall-Module -Name Az -AllVersions
This entry was posted in Cloud on by .

About SandeepSingh DBA

Hi, I am working in IT industry with having more than 10 year of experience, worked as an Oracle DBA with a Company and handling different databases like Oracle, SQL Server , DB2 etc Worked as a Development and Database Administrator.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.