How To Get Subscription ID In Azure PowerShell

This article will walk you through all the possible approaches to get subscription id in Azure using PowerShell.

How to get subscription ID in Azure PowerShell

Let us discuss all the approaches individually.

Approach-1: Using Get-AzContext

To get subscription ID in Azure PowerShell, we can use the Get-AzContext PowerShell command for this purpose. Use the below command.

(Get-AzContext).Subscription.Id

After executing the above command, I got the expected output and the Azure subscription ID, as shown in the screenshot below.

How To Get Subscription ID In Azure PowerShell

Or, we can use the below query to format the output.

Get-AzContext | Select-Object Subscription | Format-List

How To Get Subscription ID In Azure using PowerShell

Or, you can use the below query.

$mycontext = Get-AzContext
$mysubscriptionId = $mycontext.Subscription.Id
Write-Host "My Subscription ID: $mysubscriptionId"

After executing the above query, I got the expected output as shown in the screenshot below.

How do I find my Azure subscription ID?

Approach-2: Using Get-AzSubscription

We can also use the Get-AzSubscription PowerShell command for this purpose. Use the below command.

Get-AzSubscription | Select-Object Name, Id

After executing the above command, I got the expected output, as shown in the screenshot below.

Get Subscription ID In Azure PowerShell

We can also list all the subscriptions using the query below.

Get-AzSubscription | Format-Table Name, Id

After executing the above query, I got the expected output, as shown in the screenshot below.

How To find Subscription ID In Azure PowerShell

You may also like following the articles below.

Azure Virtual Machine

DOWNLOAD FREE AZURE VIRTUAL MACHINE PDF

Download our free 25+ page Azure Virtual Machine guide and master cloud deployment today!