I have a very strange problem which I cant wrap my head around.
I have a host with PowerShell 5.1 installed.
When I run the PowerShell "regulary" with the user logged in to Windows I can use the Connect-AzAccount command:
Command working
When I open the Powershell location and then select "run as different user" and login to the pwoershell with a different user the command does not work. Everytime I run Connect-AzAccount the command start but fails to open the login window returning the following error:
Command fails
Then the PowerShell session freezes and i need to close it with TaskManager.
I ran $PSVersionTable in both Powershell sessions and it is the same in both sessions:
PSVersion
I’m at a complete loss whats the issue here.
Did any of you guys experience something like this before?
2
Answers
Found a solution. Downgraded from Az.Accounts v. 3.0.0 to 2.19.0. With the older version everything works as expected.
This is a very transient issue and can be occurred due to the following reasons.
Firstly, check your execution policies which might block the script execution in the PowerShell. Set your execution policy to remote signed or set it as unrestricted and try it.
Use below to remove the context cache and try logging again into a different account.
Check if there any other profiles existed in your current PowerShell environment as shown in the below way.
Update Az PowerShell modules using
Update-Module -Name Az
if required and make sure that it is set to the latest releases.There are also some other ways for logging into the Azure with connect-AzAccount.
When I tried to login after clearing the cache context, it worked as expected.
Connect-AzAccount -UseDeviceAuthentication
as it doesn’t require to provide any credential.-Subscription
parameter.Also refer this SO by @Luuk for relevant issue.
Update:
I have faced the same error in my current PS environment now and you can also try the below workaround which worked for me.