Search code examples
azurepowershellazure-rm

Connect-AzureRmAccount - Cannot connect to Azure


While trying to connect Azure from Powershell getting below error:

PS H:\> Connect-AzureRmAccount
Connect-AzureRmAccount : An error occurred while sending the request.
At line:1 char:1
+ Connect-AzureRmAccount
+ ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Connect-AzureRmAccount], HttpRequestException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand

Solution

  • Couple of things to try :

    Sometime , powershell cmdlet doesn't give proper error message as it suppressed it , to get the actual error you can try executing with -debug attribute or you can try using DebugPreference like below.

    $DebugPreference = "Continue"
    Write-Debug -Message "Hello, World"
    

    Alternatively ,Connect-AzureRMAccount cmdlet used TLS 1.0 by default for connecting to azure and sometime it gets blocked by the organization security policy,

    Can you setting up something like below:

    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
    

    Additional reference:

    Connect-AzureRmAccount : accessing_ws_metadata_exchange_failed

    Hope it helps.