Azure PowerShell Reference
General Commands
This section provides a comprehensive reference for general Azure PowerShell cmdlets used for managing your Azure resources.
Cmdlets
Get-AzContext
Gets the current Azure PowerShell context.
Description
The Get-AzContext cmdlet retrieves the current context, which includes the subscription, tenant, and account information that you are currently logged into.
Syntax
Get-AzContext [-Scope <ContextScope>] [-ErrorAction <ActionPreference>] [-ErrorVariable <String>] [-OutBuffer <BufferMode>] [-OutVariable <String>] [-PipelineVariable <String>] [-Verbose] [-WarningAction <ActionPreference>] [-WarningVariable <String>]
Parameters
| Name | Description | Type | 
|---|---|---|
| -Scope | Specifies the scope of the context to retrieve. The acceptable values for this parameter are: User,Process. | ContextScope | 
Example
PS C:\> Get-AzContext
            Name : MySubscription Id : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx TenantId : yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy Environment : AzureCloud Account : user@example.com Subscription : MySubscription (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) SubscriptionId : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Tenant : MyTenant (yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy)
Set-AzContext
Sets the current Azure PowerShell context.
Description
The Set-AzContext cmdlet sets the current context to a specified Azure subscription, tenant, or account. This is useful when you have multiple subscriptions or accounts and need to switch between them.
Syntax
Set-AzContext [-TenantId <String>] [-SubscriptionId <String>] [-SubscriptionName <String>] [-DefaultProfile <IAzureContextContainer>] [-ErrorAction <ActionPreference>] [-ErrorVariable <String>] [-OutBuffer <BufferMode>] [-OutVariable <String>] [-PipelineVariable <String>] [-Verbose] [-WarningAction <ActionPreference>] [-WarningVariable <String>]
Parameters
| Name | Description | Type | 
|---|---|---|
| -TenantId | The ID of the tenant to set as the current context. | String | 
| -SubscriptionId | The ID of the subscription to set as the current context. | String | 
| -SubscriptionName | The name of the subscription to set as the current context. | String | 
Example
PS C:\> Set-AzContext -SubscriptionName "MyOtherSubscription"
            Name : MyOtherSubscription Id : aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa TenantId : yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy Environment : AzureCloud Account : user@example.com Subscription : MyOtherSubscription (aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa) SubscriptionId : aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa Tenant : MyTenant (yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy)
Connect-AzAccount
Connects to an Azure account.
Description
The Connect-AzAccount cmdlet logs you into your Azure account. This cmdlet can be used interactively or programmatically.
Syntax
Connect-AzAccount [-TenantId <String>] [-SubscriptionId <String>] [-SubscriptionName <String>] [-ServicePrincipal] [-CertificateThumbprint <String>] [-UseServicePrincipalPopup] [-ApplicationId <String>] [-Password <SecureString>] [-Tenant <String>] [-Environment <String>] [-Scope <ContextScope>] [-DefaultProfile <IAzureContextContainer>] [-ErrorAction <ActionPreference>] [-ErrorVariable <String>] [-OutBuffer <BufferMode>] [-OutVariable <String>] [-PipelineVariable <String>] [-Verbose] [-WarningAction <ActionPreference>] [-WarningVariable <String>]
Parameters
| Name | Description | Type | 
|---|---|---|
| -TenantId | The ID of the tenant to connect to. | String | 
| -SubscriptionId | The ID of the subscription to connect to. | String | 
| -ServicePrincipal | Log in using a service principal. | SwitchParameter | 
Example
PS C:\> Connect-AzAccount
            This will prompt for interactive login.
PS C:\> Connect-AzAccount -ServicePrincipal -TenantId "yyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy" -ApplicationId "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" -CertificateThumbprint "abcdef0123456789abcdef0123456789abcdef01"
            This logs in using a service principal with a certificate.
Disconnect-AzAccount
Disconnects from the current Azure account.
Description
The Disconnect-AzAccount cmdlet logs out of your Azure account. This clears cached credentials and resets the context.
Syntax
Disconnect-AzAccount [-Scope <ContextScope>] [-ErrorAction <ActionPreference>] [-ErrorVariable <String>] [-OutBuffer <BufferMode>] [-OutVariable <String>] [-PipelineVariable <String>] [-Verbose] [-WarningAction <ActionPreference>] [-WarningVariable <String>]
Example
PS C:\> Disconnect-AzAccount
            This disconnects the current Azure session.
Get-AzSubscription
Gets Azure subscriptions.
Description
The Get-AzSubscription cmdlet retrieves a list of Azure subscriptions that you have access to. You can filter these subscriptions by name or ID.
Syntax
Get-AzSubscription [-SubscriptionName <String>] [-SubscriptionId <String>] [-TenantId <String>] [-DefaultProfile <IAzureContextContainer>] [-ErrorAction <ActionPreference>] [-ErrorVariable <String>] [-OutBuffer <BufferMode>] [-OutVariable <String>] [-PipelineVariable <String>] [-Verbose] [-WarningAction <ActionPreference>] [-WarningVariable <String>]
Parameters
| Name | Description | Type | 
|---|---|---|
| -SubscriptionName | Name of the subscription. | String | 
| -SubscriptionId | ID of the subscription. | String | 
Example
PS C:\> Get-AzSubscription
            Name : MySubscription Id : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx State : Enabled TenantId : yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy SubscriptionPolicies : LocationPlacementId : ContentUnsafeActionAllowed : StorageAccount.isPublicProxyEnabled :