Description
Description
Hi, I'm not sure if this fits better into bug reports or questions to Az but I'm facing severe problems with the Az module preventing me to use Azure with PowerShell.
My problem:
I installed the Az module (details below at "What I did") and started testing the connection testing some basic cmdlets for querying resources lists and similar. Everything was fine until I executed one cmdlet a second time. Then I received the error "An error occurred while sending the request" I tried different cmdlets and they worked - but also only the first time. When I execute any command a second time it will fail with this error message. I can disconnect but then I can't reconnect since I'd need to execute the connect command a second time and it fails with "Connect-AzAccount : An error occurred while sending the request"
What I did:
- Installed Az by "Install-Module -Name Az -Scope CurrentUser -Repository PSGallery"
- faced the error as described
- uninstalled Az package according to the docs here [Uninstall Azure PowerShell | Microsoft Docs](https://docs.microsoft.com/en-us/powershell/azure/uninstall-az-ps?view=azps-7.2.0
- reinstalled it as above
- still facing the same error
- I opened a MS premier support ticket but they sent me here
(note: maybe the first installation was interrupted by some company update procedure killing my PS session. Maybe, I'm not sure, since it took more than 10 minutes to install without any output. That's why I uninstalled and reinstalled)
There are quite restrictive policies in place on my company's client PC as well as the network. That might be the cause but I don't know how to tackle this problem or analyze its root further. Maybe the cause is the (maybe) failed first installation of the Az package. Perhaps the uninstall guide in the docs linked above is not clean enough? I don't know what else might be the root cause since the cmdlets I tried do work for the first time in a session but afterwards they fail.
I tried using Az from MS Code until it fails. If I try to connect to Azure using a plain PS window 10 minutes later it still fails. It only recovers after some more time. Then I can run commands again, once.
I'd be very glad if you can help here.
Issue script & Debug output
> Get-AzStorageAccount
DEBUG: 12:21:57 - GetAzureStorageAccountCommand begin processing with ParameterSet 'ResourceGroupParameterSet'.
DEBUG: 12:21:57 - using account id '<REDACTED>'...
DEBUG: [Common.Authentication]: Authenticating using Account: '<REDACTED>', environment: 'AzureCloud', tenant: '<REDACTED>'
DEBUG: 12:21:57 - [SilentAuthenticator] Calling SharedTokenCacheCredential.GetTokenAsync - TenantId:'<REDACTED>', Scopes:'https://management.core.windows.net//.default', AuthorityHost:'https://login.microsoftonline.com/', UserId:'<REDACTED>'
DEBUG: SharedTokenCacheCredential.GetToken invoked. Scopes: [ https://management.core.windows.net//.default ] ParentRequestId:
DEBUG: (False) MSAL 4.30.1.0 MSAL.Desktop Windows 10 Enterprise [01/19/2022 11:21:57 - ] Azure region was not configured or could not be discovered. Not using a regional authority.
DEBUG: (False) MSAL 4.30.1.0 MSAL.Desktop Windows 10 Enterprise [01/19/2022 11:21:57] Found 1 cache accounts and 0 broker accounts
DEBUG: (False) MSAL 4.30.1.0 MSAL.Desktop Windows 10 Enterprise [01/19/2022 11:21:57] Returning 1 accounts
DEBUG: (False) MSAL 4.30.1.0 MSAL.Desktop Windows 10 Enterprise [01/19/2022 11:21:57 - ] MSAL MSAL.Desktop with assembly version '4.30.1.0'. CorrelationId(<REDACTED>)
DEBUG: (False) MSAL 4.30.1.0 MSAL.Desktop Windows 10 Enterprise [01/19/2022 11:21:57 - ] === AcquireTokenSilent Parameters ===
DEBUG: (False) MSAL 4.30.1.0 MSAL.Desktop Windows 10 Enterprise [01/19/2022 11:21:57 - ] LoginHint provided: False
DEBUG: (False) MSAL 4.30.1.0 MSAL.Desktop Windows 10 Enterprise [01/19/2022 11:21:57 - ] Account provided: True
DEBUG: (False) MSAL 4.30.1.0 MSAL.Desktop Windows 10 Enterprise [01/19/2022 11:21:57 - ] ForceRefresh: False
DEBUG: (False) MSAL 4.30.1.0 MSAL.Desktop Windows 10 Enterprise [01/19/2022 11:21:57 - ]
=== Request Data ===
Authority Provided? - True
Scopes - https://management.core.windows.net//.default
Extra Query Params Keys (space separated) -
ApiId - AcquireTokenSilent
IsConfidentialClient - False
SendX5C - False
LoginHint ? False
IsBrokerConfigured - False
HomeAccountId - False
CorrelationId - <REDACTED>
DEBUG: (False) MSAL 4.30.1.0 MSAL.Desktop Windows 10 Enterprise [01/19/2022 11:21:57 - ] === Token Acquisition (SilentRequest) started:
Authority Host: login.microsoftonline.com
DEBUG: (False) MSAL 4.30.1.0 MSAL.Desktop Windows 10 Enterprise [01/19/2022 11:21:57 - ] Azure region was not configured or could not be discovered. Not using a regional authority.
DEBUG: (False) MSAL 4.30.1.0 MSAL.Desktop Windows 10 Enterprise [01/19/2022 11:21:57 - ] Access token is not expired. Returning the found cache entry. [Current time (01/19/2022 11:21:57) - Expiration Time (01/19/2022 12:22:41 +00:00) - Extended Expiration Time (01/19/2022 12:22:41 +00:00)]
DEBUG: (False) MSAL 4.30.1.0 MSAL.Desktop Windows 10 Enterprise [01/19/2022 11:21:57 - ] Returning access token found in cache. RefreshOn exists ? False
DEBUG: (False) MSAL 4.30.1.0 MSAL.Desktop Windows 10 Enterprise [01/19/2022 11:21:57 - ] Fetched access token from host login.microsoftonline.com.
DEBUG: (False) MSAL 4.30.1.0 MSAL.Desktop Windows 10 Enterprise [01/19/2022 11:21:57 - ] === Token Acquisition finished successfully. An access token was returned with Expiration Time: 01/19/2022 12:22:41 +00:00 and Scopes https://management.core.windows.net//user_impersonation https://management.core.windows.net//.default
DEBUG: SharedTokenCacheCredential.GetToken succeeded. Scopes: [ https://management.core.windows.net//.default ] ParentRequestId: ExpiresOn: 2022-01-19T12:22:41.0000000+00:00
DEBUG: [Common.Authentication]: Received token with LoginType 'User', Tenant: '<REDACTED>', UserId: '<REDACTED>'
DEBUG: ============================ HTTP REQUEST ============================
HTTP Method:
GET
Absolute Uri:
https://management.azure.com/subscriptions/<REDACTED>/providers/Microsoft.Storage/storageAccounts?api-version=2021-06-01
Headers:
x-ms-client-request-id : <REDACTED>
accept-language : en-US
Body:
Get-AzStorageAccount : Fehler beim Senden der Anforderung.
In Zeile:1 Zeichen:1
+ Get-AzStorageAccount
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Get-AzStorageAccount], HttpRequestException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Management.Storage.GetAzureStorageAccountCommand
DEBUG: AzureQoSEvent: Module: Az.Storage:4.1.1; CommandName: Get-AzStorageAccount; PSVersion: 5.1.18362.1801; IsSuccess: False; Duration: 00:00:00.2978734; Exception: Fehler beim Senden der Anforderung.;
DEBUG: Finish sending metric.
DEBUG: 12:21:59 - GetAzureStorageAccountCommand end processing.
Environment data
Name Value
---- -----
PSVersion 5.1.18362.1801
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.18362.1801
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Module versions
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 2.7.2 Az.Accounts {Add-AzEnvironment, Clear-AzContext, Clear-AzDefault, Connect-AzAccount...}
Script 5.3.0 Az.Resources {Export-AzResourceGroup, Export-AzTemplateSpec, Get-AzDenyAssignment, Get-AzDeployment...}
Script 4.2.0 Az.Storage {Add-AzRmStorageContainerLegalHold, Add-AzStorageAccountManagementPolicyAction, Add-AzStorageAccountNetworkRule, Close-AzStorageFileHandle...}
Error output
Connect-AzAccount : Fehler beim Senden der Anforderung. (EN: An error occurred while sending the request)
In Zeile:1 Zeichen:1
+ Connect-AzAccount -Tenant $tenantID
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Connect-AzAccount], HttpRequestException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand