AZ.Accounts Module
Version: 2.11.2
Description: Microsoft Azure PowerShell account management module.
Author: Microsoft Corporation
Repository: GitHub
Overview
The AZ.Accounts module is the core module for interacting with Azure services using Azure PowerShell. It provides fundamental cmdlets for connecting to Azure, managing subscriptions, and handling authentication contexts.
Key Concepts
- Connection Context: Represents the current authentication state, including tenant, subscription, and account details.
- Subscriptions: Allows you to list, select, and manage your Azure subscriptions.
- Authentication: Supports various authentication methods like interactive login, service principal, and managed identity.
Common Cmdlets
Connect to Azure
Use Connect-AzAccount to establish a connection to your Azure account. This cmdlet will typically prompt you to log in interactively.
Connect-AzAccount
You can also specify a tenant:
Connect-AzAccount -Tenant "your-tenant-id"
List Subscriptions
After connecting, you can list all available subscriptions associated with your account:
Get-AzSubscription
Select a Subscription
To work with a specific subscription, you can set it as the active one:
Set-AzContext -SubscriptionId "your-subscription-id"
Or by subscription name:
Set-AzContext -SubscriptionName "Your Subscription Name"
Disconnect from Azure
To end your current Azure session:
Disconnect-AzAccount
Get Current Context
Retrieve information about your current Azure connection context:
Get-AzContext
Cmdlet Reference
Connect-AzAccount
Establishes a connection to Azure.
Parameters:
| Name | Type | Description | Required |
|---|---|---|---|
| Tenant | System.String | Specifies the tenant ID or domain name of the Azure Active Directory (Azure AD) organization. | No |
| Subscription | System.String | Specifies the name or ID of the subscription to connect to. | No |
| Environment | Microsoft.Azure.Commands.Common.Authentication.Models.AzureEnvironment | Specifies the Azure environment to connect to. For example, 'AzureCloud', 'AzureChinaCloud', 'AzureUSGovernment'. | No |
Get-AzSubscription
Gets the subscriptions for the current user.
Parameters:
| Name | Type | Description | Required |
|---|---|---|---|
| SubscriptionId | System.String | Specifies the subscription ID to retrieve. | No |
Set-AzContext
Sets the current Azure context.
Parameters:
| Name | Type | Description | Required |
|---|---|---|---|
| Subscription | Microsoft.Azure.Commands.Common.Authentication.Models.AzureSubscription | Specifies the subscription object to set as the current context. | No |
| SubscriptionId | System.String | Specifies the ID of the subscription to set as the current context. | No |
| SubscriptionName | System.String | Specifies the name of the subscription to set as the current context. | No |
Disconnect-AzAccount
Disconnects from Azure.
Parameters:
This cmdlet does not take any parameters.
Examples
Example 1: Basic connection and listing subscriptions
# Connect to Azure interactively
Connect-AzAccount
# Get all subscriptions
Get-AzSubscription | Format-Table
# Set a specific subscription as active
Set-AzContext -SubscriptionId "00000000-0000-0000-0000-000000000000"
Example 2: Connecting to a specific tenant and environment
Connect-AzAccount -Tenant "contoso.onmicrosoft.com" -Environment AzureChinaCloud
Example 3: Disconnecting the current session
Disconnect-AzAccount