Virtual Geek

Tales from real IT system administrators world and non-production environment

PowerShell List All Azure Resverations

Recently in one of the Azure project my client was utilizing Azure Reservations Instances (Azure RI) they wanted a Microsoft PowerShell script from me to pull the list report. Below is the screenshot of all configured reservations on the Azure Portal.

Microsoft Azure reservations All succeded scope subscription VM RI Virtual Machine Powershell az.reservations module subscription cost optimization.png

To work on Azure Reservations with PowerShell, you require Az.Reservations module, if you don't installed on your system, you can download it with below command.

Install-Module -Name Az.Reservations -Scope CurrentUser

Microsoft Powershell Azure portal Install-Module az.reservations -scope currentuser list reservations vms azure reservations virtual machines automation.png

Every Reservation has Order ID, it is a GUID, these IDs can be retrieved using below command.

Get-AzReservationOrderId #list

Microsoft Azure portal Projects Get-AzReservationOrderId subscriptions providers microsoft.capacity applied reservations orders powershell az.reservation modules.png

Once you have Reservation Order ID, more details about it can be fetched using below one-liner cmdlet.

#Get-AzReservation -ReservationOrderId $reservationOrderId

(Get-AzReservationOrderId).AppliedReservationOrderId | % {Get-AzReservation -ReservationOrderId ($_ -split '/')[-1]}

Microsoft Azure Get-AzreservationOrderId appliedreservationOrderId Get-azReservation ReservationOrderId microsoft virtual machine reservations Powershell shared scope subscription effectiveDatetime skudescription.png

If you are looking for AzureCLI scripts use below commands to automate reports.

az reservations reservation-order list
az reservations reservation list –reservation-order-id XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXXX

Useful Articles
Part 1: Working With Azure Key Vault Using Azure PowerShell and AzureCLI
Part 2: Create a Virtual machine on Microsoft Azure
Part 3: Use a Azure VM system assigned managed identity to access Azure Key Vault
Create an Azure App registrations in Azure Active Directory using PowerShell & AzureCLI
Connect-AzureAD: One or more errors occurred. Could not load type 'System.Security.Cryptography.SHA256Cng'
Use Key Vault secret identifier url to get the secret value using Powershell
Working With Azure Key Vault Using Azure PowerShell and AzureCLI
Create key vault and secrets with access policies in Microsoft Azure
Creating a new user in Azure AD using oneliner PowerShell and Azure CLI
How to switch to other Azure AD tenant using PowerShell and Azure CLI

Go Back


Blog Search

Page Views


Follow me on Blogarama