This article will walk you through all the possible approaches to get subscription id in Azure using PowerShell.
Table of Contents
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.IdAfter executing the above command, I got the expected output and the Azure subscription ID, as shown in the screenshot below.

Or, we can use the below query to format the output.
Get-AzContext | Select-Object Subscription | Format-List
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.

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, IdAfter executing the above command, I got the expected output, as shown in the screenshot below.

We can also list all the subscriptions using the query below.
Get-AzSubscription | Format-Table Name, IdAfter executing the above query, I got the expected output, as shown in the screenshot below.

You may also like following the articles below.
- How To Check Current Subscription In Azure PowerShell
- How To Switch Subscription In Azure PowerShell
- How To Set Subscription In Azure PowerShell
- How To List The Storage Accounts In A Subscription On Azure PowerShell

I am Rajkishore, and I am a Microsoft Certified IT Consultant. I have over 14 years of experience in Microsoft Azure and AWS, with good experience in Azure Functions, Storage, Virtual Machines, Logic Apps, PowerShell Commands, CLI Commands, Machine Learning, AI, Azure Cognitive Services, DevOps, etc. Not only that, I do have good real-time experience in designing and developing cloud-native data integrations on Azure or AWS, etc. I hope you will learn from these practical Azure tutorials. Read more.
