To connect the azure account with PowerShell, we can use the Connect-AZAccount command. If we check the command parameters from the below URL, there are multiple methods we can connect to the azure account but in this article, we will use the simple methods to connect.
Using the Interactive console to connect portal
Using DeviceLogin method.
Using Credentials method.
When we use the Connect-AZAccount directly without any parameter, it will open a popup for the azure portal credential.
You need to enter your Azure credentials there.
In this method, Connect-AZAccount uses the parameter -DeviceLogin. Once you run the command, it will show the code on the console window and that code we need to enter on the website,
WARNING: To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code SAYX4512 to authenticate.
As shown in the above output, you need to enter display code on the website,https://Microsoft.com/DeviceLogin and if you are not already authenticated you need to enter Azure credentials there.
You can direct provide Azure user credentials in the Get-Credentials command and use those credentials in Connect-AZAccount .
$creds = Get-Credential Connect-AZAccount -Credential $creds
Once you enter the correct credentials, your account will be connected. But if your organization has configured the multi-factor authentication this method won’t work and likely it will produce an error.