Uninstall Az Powershell Module forcefully and completely
08 Jun 2020 Written by Ajo MathewI’m primarily using PowerShell to address Azure automation activities from running from local to Azure itself. The most painful task encountered is about upgrading PowerShell Az modules and making it work with VsCode.
After many trial and error, this is the best method I could recommend to uninstall the PowerShell Az module.
Get-installedmodule Az.*| foreach-object{Uninstall-Module -Name $_.Name -Verbose -AllVersions -force}
If you encounter running the above code snippet from the no-Admin account, switch to the Admin account. Incase Az.Accounts module is adamant in getting uninstalled, open a cmd - As Administrator and run below command. This will rid your system of Az modules.
powershell -NoProfile -NonInteractive -Command "Uninstall-Module Az.Accounts"
Few things learned the hard way when using Powershell extension with VSCode.
- Always install under user scope - never install from an Admin console unless you require it. This will make sure that VSCode does not consume much of a resource.
- If you are using a company machine, it has Admin Privilege escalation controlled. Then installing under user scope can help very much- can avoid a lot of force exists on VSCode.
if ($PSVersionTable.PSEdition -eq 'Desktop' -and (Get-Module -Name AzureRM -ListAvailable))
{
Write-Warning -Message ('Az module not installed. Having both the AzureRM and ' +'Az modules installed at the same time is not supported.')
} else{
Install-Module -Name Az -AllowClobber -Scope CurrentUser
}