PowerShell Genie

Inventory Azure resource groups

Script 1 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

Get-AzResourceGroup returns every group in the subscription the context points at, and the projection keeps the group name with its location and provisioning state.

The script

1PS> Get-AzResourceGroup | Select-Object ResourceGroupName,Location,ProvisioningState

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 ResourceGroupName Location ProvisioningState
    2 ----------------- -------- -----------------
    3 RG-DEMO eastus Succeeded
    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-AzResourceGroup | Select-Object ResourceGroupName,Location,ProvisioningState
    1. Stage 1Get-AzResourceGroupPositional values or no named parameters
    2. Stage 2Select-ObjectPositional values or no named parameters

      How it works

      Get-AzResourceGroup returns every group in the subscription the context points at, and the projection keeps the group name with its location and provisioning state.

      Adapting it

      Add a calculated property that joins the Tags hashtable into a string so cost center and owner tags appear in the same table, which is normally the reason anyone asked for the list.

      Requirements

      Az.Resources with a Connect-AzAccount session.

      If the result is unexpected

      The resource-group list is unexpectedly short.

      The current subscription or access scope may exclude the groups the operator expects.

      1. Confirm the subscription and compare one known resource-group name and location.

      Validate the result

      The report matches the intended subscription and includes its identifier.

      Keep the check reliable

      Require explicit subscription selection before inventory collection.

      Primary documentation

      PowerShell objects and pipelines documentation

      Continue
      Genie guideInventory Azure resource groups

      Get-AzResourceGroup returns every group in the subscription the context points at, and the projection keeps the group name with its location and provisioning state.