Microsoft Docs

Login-AzAccount

The Login-AzAccount cmdlet authenticates you to Azure and sets the default subscription context for subsequent Azure PowerShell commands.

Syntax

Login-AzAccount
[-SubscriptionId] <String>
[-Tenant] <String>
[-Credential] <PSCredential>
[-Environment] <String>
[-DeviceCode] <SwitchParameter>
[-UseDeviceAuthentication] <SwitchParameter>
[-Scope] <String[]>
[-SkipContextPopulation] <SwitchParameter>
[-AllowNoSubscriptions] <SwitchParameter>
[<CommonParameters>]

Parameters

NameTypeDescription
-SubscriptionIdStringSpecifies the subscription ID to set as the context.
-TenantStringThe tenant (directory) ID or domain name.
-CredentialPSCredentialCredentials for username/password authentication.
-EnvironmentStringThe Azure cloud environment (AzureCloud, AzureChinaCloud, etc.).
-DeviceCodeSwitchParameterUse device code authentication flow.
-UseDeviceAuthenticationSwitchParameterAlias for -DeviceCode.
-ScopeString[]Additional scopes to request.
-SkipContextPopulationSwitchParameterSkip storing the context for the session.
-AllowNoSubscriptionsSwitchParameterAllow login when the account has no subscriptions.

Examples

Example 1: Interactive login

Login-AzAccount

Example 2: Login using a service principal

$sp = Get-Credential
Login-AzAccount -ServicePrincipal -Tenant "contoso.onmicrosoft.com" -Credential $sp

Example 3: Authenticate with device code (non‑interactive)

Login-AzAccount -DeviceCode

Notes

  • If you have multiple subscriptions, use Set-AzContext -Subscription <IdOrName> after logging in.
  • For automation, prefer Connect-AzAccount -ServicePrincipal with a certificate or secret.
  • The cmdlet stores a token cache in %USERPROFILE%\.Azure\AzureRMContext.json.

Related Cmdlets