0

I am currently logging int Azure using

az login -u -p ""

The issue is that the email is MFA and a verification code is needed to be entered in. This login process is used for CICD. Is there a way I can automate this process without having to enter the verification code

Renee
  • 1
  • 6
  • 1
    You should be able to do this with a service principal that has the appropriate access (owners) to run all of the Powershell scripts. – fmarz10 May 22 '22 at 23:59
  • is there some example i can follow ? – Renee May 23 '22 at 00:11
  • The example code below is a good one. Take a look at it and see if it works. I would also take a look at this one as well ... https://stackoverflow.com/questions/51719507/how-to-log-in-to-azure-service-principal . – fmarz10 May 25 '22 at 12:40

1 Answers1

1

Thank you for your valuable suggestion and for directing in the right direction, @fmarz10.

Service principals with various forms of credentials, such as passwords, secret keys, and certificates, can be used to do this. After adding the role you can automate login using

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

REFERENCES

  1. Azure Service Principals
  2. Sign in with Azure PowerShell
  3. Azure Provisioning - Without manual login
SwethaKandikonda
  • 7,513
  • 2
  • 4
  • 18