I want to create the AzureProfile.json file using the Az Module command in PowerShell, so that I can import the json file anytime I want to login to Azure to start\stop my VM's.
Below is the command\script I am using to create it but it is giving me error as shown in the screenshot.
I tried using the below code as well but it gives same error.
Connect-AzAccount -UseDeviceAuthentication
Save-AzProfile -path "$PSScriptRoot\AzureProfile.json"
WARNING: Unable to acquire token for tenant 'organizations' Connect-AzAccount : DeviceCodeCredential authentication failed: Retry failed after 4 tries.
You have tried both :
Both Interactive and non-interactive mode of login.
The error is occurring while trying you communicate to azure. I am suspecting it could be an issue at a machine level or network level (proxy/firewall)
The above issue usually occurs (reproducible at my end) when there are connection issues with the Microsoft Services - blocked by proxy /firewall/GPO etc...
For a quick test you could run the below PowerShell command :
Sample Success Response :
Why the above command ?
The above end point
https://login.microsoftonline.com/organizations/oauth2/v2.0/devicecode
is hit when you useConnect-AzAccount -UseDeviceAuthentication
by powershell.If you encounter a timeout/Name unresolvable issue - the issue is with the network/machine config.