Connect-AzAccount without prompt

Viewed 5343

I am trying to login into Azure Portal by using

Connect-AzAccount

This code asks me for a prompt which I don't want, can we Auto login by using some simple config script.

1 Answers

As Joy said, you could login with the user account by credential which will no prompt, make sure your account doesn't enable the MFA.

$User = "xxx@xxxx.onmicrosoft.com"
$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

For more details, you could refer to this SO thread.

Related