The issues with the Az.Accounts package are partly due to problems with TLS (Transport Layer Security) settings in PowerShell. Here are some steps you can take to resolve them:
Set TLS to 1.2: PowerShell Gallery now requires TLS 1.2 for secure connections. Run the following command to ensure TLS 1.2 is used:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Update PowerShellGet and PackageManagement: Sometimes updating these modules can resolve download issues.
Install-Module -Name PowerShellGet -Force -AllowClobber
Install-Module -Name PackageManagement -Force -AllowClobber
Run PowerShell as Administrator: Make sure to run PowerShell with administrative privileges.
Check Proxy Settings: If you are behind a proxy, you may need to configure PowerShell to use the proxy settings.
netsh winhttp set proxy "http://yourproxy:port"
Clear the NuGet cache: Sometimes clearing the NuGet cache can help if the module is stuck.
nuget locals all -clear
Manually install the NuGet provider: If the above steps don’t work, you can manually install the NuGet provider.
- Download the NuGet provider from this link.
- Place the downloaded file in a folder, for example:
C:\NuGet
. - Run the following command to install the provider:
Install-PackageProvider -Name NuGet -SourceLocation "C:\NuGet" -Force
Another option is to place the files from the ZIP archive into the folder %ProgramFiles%\WindowsPowerShell\Modules\Az.Accounts
.
Other possible causes of issues with the Az.Accounts package
Here are some additional causes and solutions for problems with the Az.Accounts package:
Check if there are any network issues that might be interfering with the connection to the PowerShell Gallery. This can be caused by firewall settings or network restrictions. An example error message is:
WARNING: Source Location 'https://www.powershellgallery.com/api/v2/package/Az.Accounts/1.7.4' is not valid.
PackageManagement\Install-Package : Package 'Az.Accounts' failed to download.
At C:\Program Files\WindowsPowershell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1772 char:21
+ ... $null = PackageManagement\Install-Package @PSBoundParameters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (C:\Users\{username}....Accounts.nupkg:String) [Install-Package], Exception
+ FullyQualifiedErrorId : PackageFailedInstallOrDownload,Microsoft.Powershell.PackageManagement.Cmdlets.InstallPackage
We also occasionally see this message:
Outdated PowerShell version can cause issues with the Az.Accounts package
Make sure you are using at least the latest version of PowerShell. Older versions can cause compatibility issues with certain modules.
You can check your version with:
$PSVersionTable.PSVersion
Outdated NuGet provider
The NuGet provider used by PowerShell to download modules may be outdated. Try updating the NuGet provider:
Install-PackageProvider -Name NuGet -Force -Scope CurrentUser
Conflicting versions of the Az module
If multiple versions of the Az module are installed, conflicts may occur. Remove older versions and install the latest version:
Get-InstalledModule -Name Az -AllVersions | Uninstall-Module
Install-Module -Name Az -AllowClobber -Force
Issues with the PowerShell Gallery
Sometimes there may be temporary issues with the PowerShell Gallery. Check the status of the PowerShell Gallery at status.powershellgallery.com.
Proxy settings
If you are behind a proxy, you may need to configure the proxy settings in PowerShell:
netsh winhttp set proxy "http://yourproxy:port"
Lack of permissions
Make sure you are running PowerShell with administrative rights. This is sometimes required to install or update modules.
Network issues
Check if there are any network issues interfering with the connection to the PowerShell Gallery. This could be caused by firewall settings or network restrictions.
Finally, you may also decide to completely remove the Az modules from the system. Microsoft has published a blog post on this:
Uninstall Azure PowerShell | Microsoft Learn
More information about PowerShell can be found here. An example can be found here.