Authenticate with Azure PowerShell

Learn how to sign in to Azure using PowerShell so you can manage resources, automate deployments, and integrate with CI/CD pipelines.

Prerequisites

Login Methods

Interactive login (Device code)

Best for developers working locally.

Connect-AzAccount -UseDeviceAuthentication

Service Principal with Secret

Ideal for automation scripts.

$tenantId   = "YOUR_TENANT_ID"
$appId      = "YOUR_APP_ID"
$secret     = "YOUR_CLIENT_SECRET"
Connect-AzAccount -ServicePrincipal -Tenant $tenantId -ApplicationId $appId -Credential (New-Object System.Management.Automation.PSCredential($appId,(ConvertTo-SecureString $secret -AsPlainText -Force)))

Managed Identity (Azure VM, App Service)

Used when the script runs in an Azure resource with a managed identity enabled.

Connect-AzAccount -Identity

Verification

After logging in, confirm the context:

Get-AzContext

Common Issues

IssueResolution
Invalid credentialsVerify client secret or certificate details.
Insufficient permissionsAssign appropriate role (e.g., Contributor) to the service principal or managed identity.
Module not foundInstall with Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force.

Next Steps