Connect-AzAccount

Connect to Azure account

The Connect-AzAccount cmdlet signs in to Azure with an active subscription. This is the first cmdlet that you typically run when using Azure PowerShell.

Syntax

Connect-AzAccount
   [-EnvironmentName ]
   [-TenantId ]
   [-Subscription ]
   [-SubscriptionId ]
   [-Username ]
   [-Password ]
   [-ServicePrincipal]
   [-CertificateThumbprint ]
   [-Tenant ]
   [-Force]
   [-UseDeviceAuthentication]
   [-Scope ]
   [-ShowProgress]
   [-WhatIf]
   [-Confirm]
   []

Description

The Connect-AzAccount cmdlet signs you in to Azure. After you sign in, you can select an active subscription to use for the current session.

Examples

Example 1: Sign in interactively

The following command prompts you to enter your Azure credentials:

Connect-AzAccount

Example 2: Sign in with a username

This command signs you in to Azure with the specified username:

Connect-AzAccount -Username "your_email@example.com"

Example 3: Sign in to a specific tenant

This command signs you in to a specific tenant by its ID:

Connect-AzAccount -TenantId "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

Parameters

Name Type Description
-EnvironmentName String Specifies the Azure environment to connect to. For example, "AzureCloud" for the public Azure cloud, or "AzureUSGovernment" for the US Government cloud. You can also use a custom environment name.
-TenantId String Specifies the tenant ID or the domain name of the tenant.
-Subscription String Specifies the name of the subscription to use for the session.
-SubscriptionId Guid Specifies the ID of the subscription to use for the session.
-Username String Specifies the user name for authentication.
-Password String Specifies the password for authentication. Use this parameter with caution as it exposes your password in command history.
-ServicePrincipal Switch Indicates that the sign-in is for a service principal.
-CertificateThumbprint String Specifies the thumbprint of the X.509 certificate to use for authentication.
-Tenant String Specifies the tenant ID or domain name. This is an alias for TenantId.
-Force Switch Forces the command to run without asking for user confirmation.
-UseDeviceAuthentication Switch Use device authentication flow to sign in. This is useful for environments where interactive login is not possible.
-Scope String Specifies the scope of the tenant for which the credentials apply.
-ShowProgress Switch Displays progress for the command.

Input Types

None. You can pipe input to this cmdlet.

Return Values

Microsoft.Azure.Commands.Common.Authentication.IAuthenticatedAccount

The cmdlet returns an authenticated account object.

Notes

  • If you don't specify any parameters, the cmdlet prompts you for your credentials and then displays a list of subscriptions you have access to. You can then select the subscription you want to use.
  • For service principal authentication, use the -ServicePrincipal and either -Username (for the application ID) and -Password, or -CertificateThumbprint.

Related Links