Created
December 2, 2025 21:30
-
-
Save caseywatson/6482bc94b40ddbee8f2069ab2d11d3ee to your computer and use it in GitHub Desktop.
Retrieve Azure VM pricing meter IDs for a given region (i.e., `armRegionName`)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # PowerShell script to retrieve Azure VM pricing information | |
| # Fetches armSkuName, meterName, meterId, reservationTerm for Virtual Machines | |
| # Includes both Consumption and Reservation prices | |
| # Allows specifying armRegionName as a parameter (optional) | |
| # Exports results to a CSV file | |
| param( | |
| [string]$armRegionName = "", | |
| [string]$outputFile = "vm_pricing.csv" | |
| ) | |
| # Build the filter string | |
| $filter = "serviceName eq 'Virtual Machines'" | |
| if ($armRegionName) { | |
| $filter += " and armRegionName eq '$armRegionName'" | |
| } | |
| # Define the initial API URL | |
| $apiUrl = "https://prices.azure.com/api/retail/prices?api-version=2023-01-01-preview&`$filter=$filter" | |
| # Initialize an array to store all results | |
| $allResults = @() | |
| do { | |
| # Invoke the REST API | |
| $response = Invoke-RestMethod -Uri $apiUrl -Method Get | |
| # Add the current page's items to the results | |
| $allResults += $response.Items | Select-Object skuName, armSkuName, meterName, meterId, reservationTerm | |
| # Update the URL to the next page if available | |
| $apiUrl = $response.NextPageLink | |
| } while ($apiUrl) | |
| # Export the results to CSV | |
| $allResults | Export-Csv -Path $outputFile -NoTypeInformation | |
| Write-Output "Results exported to $outputFile" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment