Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect-AzAccount - how to avoid azure device authentication?

I have installed the PowerShell 6.1.3 version and I want to get a connection to the Azure account using the following Azure PowerShell command:

Connect-AzAccount -Tenant <tenantId> -Subscription <subId>

After entering this command I get the warning with the url and some code. Then I have to go to the URL and enter the code there. After that, I get a connection to the Azure account.

Are there any ways to avoid this confirmation?

I've also tried to do it using the following command:

az login -u <username> -p <password>

This command only returns some account information(subscriptionId, tenantId etc) but it doesn't install a connection to this account.

like image 311
agawa17 Avatar asked Feb 26 '19 17:02

agawa17


People also ask

What does connect-AzAccount do?

Description. The Connect-AzAccount cmdlet connects to Azure with an authenticated account for use with cmdlets from the Az PowerShell modules. You can use this authenticated account only with Azure Resource Manager requests.

How do I pass credentials in PowerShell without prompt?

$cred = Get-Credential without asking for prompts in powershell - Microsoft Tech Community.

How do I connect-AzAccount to PowerShell?

Open the PowerShell console. Run Add-AzAccount or Connect-AzAccount or Login-AzAccount command. After the successful authentication validation, it will direct you to the PowerShell console. To see the profile file details, you can run the ls -lrt command to view the time and other details of JSON.

Which PowerShell command is used to authenticate to Azure?

Password-based authentication For more information on creating service principals, see Create an Azure service principal with Azure PowerShell. To get the service principal's credentials as the appropriate object, use the Get-Credential cmdlet. This cmdlet presents a prompt for a username and password.

How do I connect to Azure with an authenticated account?

The Connect-AzAccount cmdlet connects to Azure with an authenticated account for use with cmdlets from the Az PowerShell modules. You can use this authenticated account only with Azure Resource Manager requests. To add an authenticated account for use with Service Management, use the Add-AzureAccount cmdlet from the Azure PowerShell module.

Which browser should I use to authenticate to my Azure account?

When you use the -UseDeviceAuthentication option, Connect-AzAccount lets you manually pick which browser you want to use for Azure authentication. In my case, I used Chrome in incognito mode to perform Azure authentication, and I was finally able to authenticate with my Azure AD account ("[email protected]") successfully.

How do I authenticate with azure using organizational ID credentials?

This account authenticates with Azure using organizational ID credentials. The first command stores the service principal credentials in the $Credential variable. The second command connects the specified Azure tenant using the service principal credentials stored in the $Credential variable.

How do I connect to an Azure Resource Manager account?

The first command will prompt for user credentials (username and password), and then stores them in the $Credential variable. The second command connects to an Azure account using the credentials stored in $Credential. This account authenticates with Azure Resource Manager using organizational ID credentials.


1 Answers

1.To login with the user account, try the command as below, make sure your account doesn't enable the MFA(Multi-Factor Authentication).

$User = "[email protected]"
$PWord = ConvertTo-SecureString -String "<Password>" -AsPlainText -Force
$tenant = "<tenant id>"
$subscription = "<subscription id>"
$Credential = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $User,$PWord
Connect-AzAccount -Credential $Credential -Tenant $tenant -Subscription $subscription

enter image description here

2.You can also use a service principal to login, use the command as below.

$azureAplicationId ="Azure AD Application Id"
$azureTenantId= "Your Tenant Id"
$azurePassword = ConvertTo-SecureString "strong password" -AsPlainText -Force
$psCred = New-Object System.Management.Automation.PSCredential($azureAplicationId , $azurePassword)
Connect-AzAccount -Credential $psCred -TenantId $azureTenantId  -ServicePrincipal 

See a similar issue I answered here, it use the old AzureRM module, for Az, just change the last line.

If you are not familiar with service principal, Also see : How to: Use the portal to create an Azure AD application and service principal that can access resources, the application id and authentication key are the Azure AD Application Id and strong password you need.

like image 54
Joy Wang Avatar answered Sep 29 '22 16:09

Joy Wang