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 the code in the given url:
Now in powershell you will get this type of output:
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