> ## Content Index
> Fetch the complete content index at: https://codeisahighway.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Automating the extraction of Azure Regions resiliency information
- URL: https://codeisahighway.com/automating-the-extraction-of-azure-regions-resiliency-information/
- Published: 2025-01-30T18:35:11.000Z
- Updated: 2026-07-30T19:45:03.000Z
- Author: Stephane Lapointe
- Tags: Azure CLI, Automation, Governance, #Import 2026-09-04 10:31, #Import 2026-09-04 13:56

Azure paired regions and zone compatible regions are fundamental for ensuring redundancy and high availability of your applications in the cloud. Understanding the geography, physical regions, and their pairings can help you make informed decisions when architecting solutions on Azure. In this guide, we'll walk through how you can automate the extraction of Azure regions information using PowerShell and Azure CLI and format them as you like.

## Prerequisites

- Azure CLI installed on your machine. You can download it from [here](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?wt.mc%5Fid=AZ-MVP-5001613&ref=codeisahighway.com).
- PowerShell installed on your machine. You can download it from [here](https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell?wt.mc%5Fid=AZ-MVP-5001613&ref=codeisahighway.com).
- You need to be logged in to your Azure account using `az login`.

## PowerShell Script to Extract Azure Paired Regions

Below is a PowerShell script that uses Azure CLI to list all the regions, filters them to get physical regions, and formats the output to display the geography group, geography, region name, and paired region.

```powershell
# Retrieve all Azure regions
$results = az account list-locations | ConvertFrom-Json

# Filter only physical regions
$physicalResults = $results | Where-Object { $_.metadata.regionType -eq 'Physical' }

# Select and format the desired properties
$formattedResults = $physicalResults | Select-Object `
    @{name="GeographyGroup"; Expression = {$_.metadata.geographyGroup}}, `
    @{name="Geography"; Expression = {$_.metadata.geography}}, `
    @{name="Region"; Expression = {$_.name}}, `
    @{name="PairedRegion"; Expression = {$_.metadata.pairedRegion[0].name}}

# Convert to JSON format with depth for nested objects
$jsonOutput = $formattedResults | ConvertTo-Json -Depth 5

# Output the JSON result
$jsonOutput
```

## Explanation

- **Retrieve Regions**: The command `az account list-locations` retrieves all the Azure regions available for your subscription. We use `ConvertFrom-Json` to convert the output into a PowerShell object for easier manipulation.
- **Filter Physical Regions**: We filter the regions to include only those with a `regionType` of 'Physical'.
- **Select and Format Properties**: We use `Select-Object` to extract specific properties and rename them for clarity. This includes the geography group, geography, region name, and the name of the paired region.
- **Convert to JSON**: Finally, we convert the filtered and formatted data back into JSON format using `ConvertTo-Json`, allowing for easy consumption in other tools or systems.

Using that kind of information, we can automate and ease all type of decisions. Here is an example where we could use that strategy to produce Azure Resource Graph statements and augment queries with resiliency information.

```powershell
$results = az account list-locations | ConvertFrom-Json

$physicalResults = $results | Where-Object { $_.metadata.regionType -eq 'Physical' }

$results = $physicalResults `
    | Select-Object @{ name = "GeographyGroup"; Expression = { $_.metadata.geographyGroup } }, `
        @{ name = "Geography"; Expression = { $_.metadata.geography } }, `
        @{ name = "region"; Expression = { $_.name } }, `
        @{ name = "paired_region"; Expression = { $_.metadata.pairedRegion[0].name } }, `
        @{ name = "zones"; Expression = { $_.availabilityZoneMappings } } `
    | Where-Object GeographyGroup -in ('US', 'Canada')

# extract regions that have a paired region
$PairedRegions = $results `
    | Where-Object paired_region -ne $null `
    | Sort-Object Region `
    | Select-Object -ExpandProperty region

$joinedStringValues = "'$($PairedRegions -join "','")'"
# Produce a ARG statement for identifying resources in paired regions
"| extend drp_in_paired_region = case(location in ($joinedStringValues), true, false)"

# extract regions that have a zones support
$RegionsWithZones = $results `
    | Where-Object zones -ne $null `
    | Sort-Object Region `
    | Select-Object -ExpandProperty region    

$joinedStringValues = "'$($RegionsWithZones -join "','")'"
# Produce a ARG statement for identifying resources in regions with zones support
"| extend drp_region_support_az = case(location in ($joinedStringValues), true, false)"    
```

This script will produce the following outputs:

```powershell
| extend drp_in_paired_region = case(location in ('canadacentral','canadaeast','centralus','centraluseuap','eastus','eastus2','eastus2euap','eastusstg','northcentralus','southcentralus','southcentralusstg','westcentralus','westus','westus2','westus3'), true, false)

| extend drp_region_support_az = case(location in ('canadacentral','centralus','eastus','eastus2','eastus2euap','southcentralus','westus2','westus3'), true, false)
```

## Conclusion

This provides an automated way to extract and use Azure's regional resiliency information, which can be crucial for planning and deploying resilient and high-available applications. By leveraging Azure CLI and PowerShell, you can easily integrate this process into your existing automation workflows.

## References

- [Azure CLI - Install and Setup](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?wt.mc%5Fid=AZ-MVP-5001613&ref=codeisahighway.com)
- [PowerShell - Install and Setup](https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell?wt.mc%5Fid=AZ-MVP-5001613&ref=codeisahighway.com)
- [Azure Paired Regions Documentation](https://learn.microsoft.com/en-us/azure/best-practices-availability-paired-regions?wt.mc%5Fid=AZ-MVP-5001613&ref=codeisahighway.com)

Feel free to modify the script to suit your specific needs, such as outputting the results to a file or integrating with other systems like Azure Resource Graph (ARG) for further processing. Happy automating!