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
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.