Home > Enterprise >  Az login without manual interaction
Az login without manual interaction

Time:07-07

I am trying to automate azure login in a powershell script and for that, I am using the below command as suggested in the Microsoft doc here:

az login --tenant <tenant> --use-device-code

But the script is pausing here with the below warning expecting us to open browser and enter a code.

To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code <code> to authenticate.

How do I automate the login in my powershell script?

Edit: The intention of this post is to understand the working of --use-device-code and get it working as expected.

CodePudding user response:

This is how az login --use-device-code works:

enter image description here

Enter the code in the given url:

enter image description here

Now in powershell you will get this type of output:

enter image description here

CodePudding user response:

Another way to do this is to run your script on an Azure VM with a managed identity. In that instance, no credentials are needed. All you need to do is run:

az login --identity

https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/how-to-use-vm-sign-in

  • Related