PowerShell Genie

Inventory Azure subscriptions

Script 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

Get-AzSubscription lists the subscriptions the signed-in identity can see in the current tenant, and the projection keeps name, ID, tenant ID and State.

The script

1PS> Get-AzSubscription | Select-Object Name,Id,State,IsDefault

Script reader

Inspect before you run

Inspection only

Inspect the script below. It does not run in this browser.

Inspection only — no command has run.

    Show reference output
    1 Name Id TenantId State
    2 ---- -- -------- -----
    3 Production 11111111-2222-3333-4444-555555555555 aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee Enabled
    Inspect this example’s structure

    Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.

    Get-AzSubscription | Select-Object Name,Id,State,IsDefault
    1. Stage 1Get-AzSubscriptionPositional values or no named parameters
    2. Stage 2Select-ObjectPositional values or no named parameters

      How it works

      Get-AzSubscription lists the subscriptions the signed-in identity can see in the current tenant, and the projection keeps name, ID, tenant ID and State. Use Get-AzContext to see which subscription subsequent Az commands will target.

      Adapting it

      Follow this with Set-AzContext -SubscriptionId to move the session deliberately instead of relying on whichever subscription the login happened to select.

      Requirements

      Az.Accounts with an active Connect-AzAccount session.

      If the result is unexpected

      An Azure subscription is missing from the list.

      The signed-in identity may lack access, or the context may belong to another tenant or cloud.

      1. Inspect the Azure account context and compare a known subscription identifier with the access granted to that identity.

      Validate the result

      The intended subscription is returned under the expected tenant.

      Keep the check reliable

      Use explicit tenant and subscription identifiers in scheduled reports.

      Primary documentation

      Microsoft 365, Entra and Azure documentation

      Continue
      Genie guideInventory Azure subscriptions

      Get-AzSubscription lists the subscriptions the signed-in identity can see in the current tenant, and the projection keeps name, ID, tenant ID and State.