Install/Remove AZ module in Powershell for Azure
Following prerequisite done on window machine before install
- For install powershell be the latest version above 7.
- 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
- 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.
- 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