25

In Azure Classic / Service Management, Get-AzureSubscription would give a list of subscriptions in the Tenant with an indicator of which was current.

There was also a Get-AzureSubscription -Current flag that would give you just the current subscription.

Is there a way to find the current subscription in AzureRM.Profile?

Rasmus
  • 556
  • 3
  • 19
Michael B
  • 11,887
  • 6
  • 38
  • 74

4 Answers4

58

Get-AzureRmContext gives you info about the selected subscription, default storage account, etc.

(Get-AzureRmContext).Subscription gives you the current subscription.

BenV
  • 12,052
  • 13
  • 64
  • 92
  • Ha! it does, At some point in looking for the answer I looked at that as well. Guess I should stay off the stupid juice for a while... Thanks – Michael B Jan 21 '16 at 16:59
  • Took me a while to figure it out after I upgraded to the AzureRM modules too. – BenV Jan 21 '16 at 17:07
10

Now you can use the new Az commands

Get-AzContext

Jucer
  • 101
  • 1
  • 5
  • 1
    Hi Jucer, welcome to stackoverflow. Can you provide more context as to what information the `Get-AzContext` command provides, and possibly whether or not the accepted answer no longer applies? Your answer is fairly terse. – cronburg May 17 '19 at 16:36
1

You can also use Get-AzureRmSubscription

$sub = Get-AzureRmSubscription
$sub.SubscriptionId

This will give you the SubscriptionId

Rasmus
  • 556
  • 3
  • 19
Ahmed Elnably
  • 461
  • 3
  • 5
0

Get-AzureRmContext and Get-AzContext both are valid but Get-AzContext is latest way to do it

You might have seen or used Azure PowerShell commands that used an -AzureRM format. In December 2018 Microsoft released for general availability the AzureRM module replacement with the Az module. This new module has several features, notably a shortened cmdlet noun prefix of -Az, which replaces AzureRM. The Az module ships with backwards compatibility for the AzureRM module, so the -AzureRM cmdlet format will work.

Mirza
  • 33
  • 5