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.
Connect-AzAccount
[-EnvironmentName ]
[-TenantId ]
[-Subscription ]
[-SubscriptionId ]
[-Username ]
[-Password ]
[-ServicePrincipal]
[-CertificateThumbprint ]
[-Tenant ]
[-Force]
[-UseDeviceAuthentication]
[-Scope ]
[-ShowProgress]
[-WhatIf]
[-Confirm]
[]
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.
The following command prompts you to enter your Azure credentials:
Connect-AzAccount
This command signs you in to Azure with the specified username:
Connect-AzAccount -Username "your_email@example.com"
This command signs you in to a specific tenant by its ID:
Connect-AzAccount -TenantId "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
| 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. |
None. You can pipe input to this cmdlet.
Microsoft.Azure.Commands.Common.Authentication.IAuthenticatedAccount
The cmdlet returns an authenticated account object.
-ServicePrincipal and either -Username (for the application ID) and -Password, or -CertificateThumbprint.-Password parameter directly in scripts. Consider using secure methods like Azure Key Vault or environment variables for storing credentials.
Connect-AzAccount -UseDeviceAuthentication option for non-interactive environments.