Errors while trying to login to Azure subscription RRS feed

  • Question

  • Hi,

    I have 6 subscriptions access (different user accounts) in separate tenants. I would like to get resources details from all subscriptions using PowerShell script.
    And I am using below script to authenticate a user and to get access to Azure subscription. The script is working fine for few subscriptions. 
    $useraccount= 'xxxxxxxxxxxxxxxxxxxxxxxxxxx'
    $password = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    $AzureSubscriptionID = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'

    $SecurePassword = ConvertTo-SecureString -AsPlainText $password -Force
    $Cred = New-Object System.Management.Automation.PSCredential -ArgumentList $useraccount, $SecurePassword
    (Login-AzureRmAccount -Credential $Cred -SubscriptionId $AzureSubscriptionID -ErrorAction Stop) | Out-Null
    And below is the error message for few accounts.
    Login-AzureRmAccount : AADSTS70002: Error validating credentials. AADSTS50126: Invalid username or password
    Trace ID: 485faec7-6089-402a-b63a-a608f0584900
    Correlation ID: dad46558-700f-4eb4-90cb-f81480c7e7de
    Timestamp: 2018-10-16 10:31:02Z: The remote server returned an error: (400) Bad Request.

    Here I am passing the valid Username and password and able to get an access when I use the single command "Login-AzureRmAccount".
    But getting the error when trying with the script.

    Can someone help me here

    • Edited by Eswari303 Wednesday, October 17, 2018 4:21 AM
    • Moved by Bill_Stewart Monday, January 7, 2019 8:11 PM This is not "scripts on demand"
    Wednesday, October 17, 2018 4:19 AM

All replies

  • Hello Eswari303,

    I have written a script that does the job for you. Please use the below link to download the script:




    Thanks, Manjunath

    Friday, November 9, 2018 7:54 PM