3

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.

Joseph
  • 530
  • 3
  • 15
  • 37
  • Have you tried `$Credential = Get-Credential; Connect-AzAccount -Credential $Credential` ? – Theo Apr 08 '20 at 10:46
  • 1
    I tried but it asks for a prompt, the accepted answer below doesn't requires a prompt. Thanks! – Joseph Apr 08 '20 at 14:46

1 Answers1

6

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.

Joey Cai
  • 18,968
  • 1
  • 20
  • 30