Az.Accounts Module

The Az.Accounts module provides cmdlets for managing Azure accounts and subscriptions. This is a foundational module for interacting with Azure resources via PowerShell.

Overview

This module enables you to:

Cmdlets

Connect-AzAccount

Connects to an Azure account.

Synopsis
Connect-AzAccount [-TenantId ] [-ApplicationId ] [-Credential ] [-EnvironmentName ] []
Description

The Connect-AzAccount cmdlet connects you to your Azure account. After you run this cmdlet, you are prompted to authenticate with Azure. If you have multiple subscriptions, you can use the -TenantId parameter to specify a tenant and then select a subscription.

Parameters
Name Type Description Required
TenantId String The Azure Active Directory tenant ID. No
ApplicationId String The client ID for a service principal. No
Credential PSCredential A username and password credential object. No
EnvironmentName String The Azure environment to connect to (e.g., AzureCloud, AzureUSGovernment). No

Example 1: Connect to Azure Cloud

Connect-AzAccount

Example 2: Connect to a specific tenant

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

Get-AzSubscription

Gets a list of subscriptions available to the user.

Synopsis
Get-AzSubscription [-SubscriptionId ] []
Description

The Get-AzSubscription cmdlet returns a list of subscriptions that are available to the authenticated user. You can filter the list by subscription ID.

Parameters
Name Type Description Required
SubscriptionId String The ID of the subscription to retrieve. No

Example 1: Get all subscriptions

Get-AzSubscription

Example 2: Get a specific subscription by ID

Get-AzSubscription -SubscriptionId "yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy"

Set-AzContext

Sets the current Azure context.

Synopsis
Set-AzContext -TenantId  [-SubscriptionId ] [-SubscriptionName ] []
Description

The Set-AzContext cmdlet allows you to change the active subscription for your current PowerShell session. This is useful when you have access to multiple subscriptions.

Parameters
Name Type Description Required
TenantId String The Azure AD tenant ID. Yes
SubscriptionId String The subscription ID to set as active. No
SubscriptionName String The subscription name to set as active. No

Example 1: Set context to a subscription by ID

Set-AzContext -SubscriptionId "yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy"

Example 2: Set context to a subscription by name

Set-AzContext -SubscriptionName "My Development Subscription"

Disconnect-AzAccount

Disconnects from the current Azure account.

Synopsis
Disconnect-AzAccount []
Description

The Disconnect-AzAccount cmdlet signs out the user from Azure. This cmdlet clears the cached credentials and closes the connection.

Example 1: Disconnect from Azure

Disconnect-AzAccount
Note: Ensure you have the Azure PowerShell Az module installed. You can install it using:
Install-Module -Name Az -Scope CurrentUser -Force -AllowClobber