1

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.

enter image description here

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.

SRP
  • 999
  • 4
  • 21
  • 39

2 Answers2

1

From the error message, it looks like the authentication of your account is failing in the Browser pop-up that comes after Login-AzAccount.

I ran the first set of commands and it ran successfully.

Powershell:

enter image description here

Created File:

enter image description here

Note that my PowerShell version is 5.7.0.18831.

Harshita Singh
  • 4,590
  • 1
  • 10
  • 13
  • I tried the same it gives me error my PS version is 5.1 WARNING: Unable to acquire token for tenant 'organizations' Connect-AzAccount : An error occurred while sending the request. At line:1 char:1 + Connect-AzAccount + ~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [Connect-AzAccount], HttpRequestException + FullyQualifiedErrorId : Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand – SRP Jan 19 '21 at 10:00
  • Did authentication succeed in the browser? Also, try running these commands in 'Powershell' instead of 'Powershell ISE'. – Harshita Singh Jan 19 '21 at 10:03
  • Check out this issue once: https://github.com/Azure/azure-powershell/issues/13340 – Harshita Singh Jan 19 '21 at 10:06
  • The above command I executed in PowerShell like you, after entering that command a popup windows appeared which asked me to enter the username and after clicking on Next it asked me to enter the password and after entering the password and i clicked on sign in and then i gave me the error in PowerShell. – SRP Jan 19 '21 at 10:07
  • Also, try performing steps mentioned in this issue: https://stackoverflow.com/questions/63295518/azure-digital-twin-authentication-interactivebrowsercredential-authentication by SatishBoddu – Harshita Singh Jan 19 '21 at 10:09
  • I think it can be related to your browser: it can be blocking pop- ups/cache is there. Pls check above issue once and try the browser steps only. – Harshita Singh Jan 19 '21 at 10:10
  • Tried it, same error, cleared cache and enabled pop-ups from browser settings, restarted the browser..still throws the same error as shown in above comment. – SRP Jan 19 '21 at 10:19
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/227524/discussion-between-singhh-msft-and-srp). – Harshita Singh Jan 19 '21 at 10:20
1

You have tried both :

  • Connect-AzAccount -UseDeviceAuthentication
  • Login-AzAccount

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)

enter image description here

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 :

Invoke-WebRequest -Uri "https://login.microsoftonline.com/organizations/oauth2/v2.0/devicecode" -Body "client_id=1950a258-227b-4e31-a9cf-717495945fc2&scope=https%3A%2F%2Fmanagement.core.windows.net%2F%2F.default+offline_access+profile+openid" -Method Post

Sample Success Response :

enter image description here

Why the above command ?

The above end point https://login.microsoftonline.com/organizations/oauth2/v2.0/devicecode is hit when you use Connect-AzAccount -UseDeviceAuthentication by powershell.

enter image description here

If you encounter a timeout/Name unresolvable issue - the issue is with the network/machine config.

Satya V
  • 3,811
  • 1
  • 6
  • 9
  • Did you get the code for the -UseDeviceAuthentication ? – Satya V Jan 19 '21 at 10:20
  • Yes, i received the same success response like you after triggering the command provided by you. – SRP Jan 19 '21 at 10:21
  • How about when you run `Connect-AzAccount -UseDeviceAuthentication` – Satya V Jan 19 '21 at 10:40
  • Yes, when tried with PowerShell by entering "Connect-AzAccount -UseDeviceAuthentication" command after entering the command on browser it says "You have signed in to the Microsoft Azure PowerShell application on your device. You may now close this window." and on PowerShell prompt it gives error "WARNING: Unable to acquire token for tenant 'organizations' Connect-AzAccount : An error occurred while sending the request. At line:1 char:1 + Connect-AzAccount -UseDeviceAuthentication" + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ – SRP Jan 19 '21 at 10:47
  • The query needs a further information & probing. Please send mail to AzCommunity [at] microsoft dot com with subject: "ATTN: Sathya" and a link to this forum thread (for context). – Satya V Jan 19 '21 at 11:13