Use Azure REST API With PowerShell

This Microsoft Azure REST API post will show how to use REST API calls with Azure using PowerShell 7.

Microsoft Azure REST API offers developers programmatic access to Azure services using API calls without warpers like Azure PowerShell. In some scenarios where Azure PowerShell cannot configure resources, REST API can help.

The REST API library allows us to use the PowerShell invoke-azrestmethod the cmdlet to make API calls like Get, Post, Delete and configure resources.

In the following PowerShell script, we will make a GET API call to Azure and get a list of all the Azure VMs under a specific subscription.

Requirements

Before you get to the code, you must install the Azure PowerShell module and authenticate to Azure using a login name and password or a certificate.

The check the status of all the VM in the subscription, run the following script.

$patchParams = @{
  ResourceProviderName = 'Microsoft.Compute'
  ResourceType = 'virtualMachines'
  ApiVersion = '2023-03-01&statusOnly=true'
  Payload = @{
     }
  Method = 'GET'
}
Invoke-AzRestMethod @patchParams  

The output will show the status of all the VMs.


Posted

in

,

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.