Hi @Richkm
Welcome to Microsoft Q&A Platform, thanks for posting your query here.
If you need connect automatically, you can't use an account with MFA
You can create a Service principal for that script, and authenticate in the following way
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $ApplicationId, $SecuredPassword
Connect-AzAccount -ServicePrincipal -TenantId $TenantId -Credential $Credential
Also, you can authenticate the services principal with certificate, and connect in the following way
$Thumbprint = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
$TenantId = 'yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyy'
$ApplicationId = '00000000-0000-0000-0000-00000000'
Connect-AzAccount -CertificateThumbprint $Thumbprint -ApplicationId $ApplicationId -Tenant $TenantId -ServicePrincipal
You can create a service principal with a certificate following this tutorial https://learn.microsoft.com/en-us/azure/active-directory/develop/howto-authenticate-service-principal-powershell
Hope this helps,
Carlos Solís Salazar
----------
Please "Accept as Answer" and/or Upvote if any of the above helped so that, it can help others in the community looking for remediation for similar issues.