Using the Azure REST API in PowerShell – ASM & ARM

This post covers using the Azure REST API in PowerShell.

First of you need to install the latest and greatest Azure PowerShell Module on your machine. Best place to do this is to install the good old fashioned MSI available from https://github.com/Azure/azure-powershell/releases

Once you have the latest Azure PowerShell Module on your machine, you’ll need to restart.

For the remainder of this post we will be focusing on the Rest API for Azure, the reference for the Azure Classic Rest API is here and the Rest API reference for Azure ARM is here.

The script below will have you Logon to (new) Azure from PowerShell only. Then the script can handle two separate Rest API calls:

  • Rest API call against Azure Classic
  • Rest API call against Azure ARM

The function for the Rest API auth will handle both Classic & ARM. Feel free to use the script below as a start to test yourself, it doesn’t change anything and only does a ‘GET’ for information.

By the way, if you want to run something similar in the Chrome plugin Postman, this article walks you through it.

To get the Authorisation code in the Article, from the PowerShell above, the following will give you what you need and send it direct to the clipboard

$global:authResultASM.CreateAuthorizationHeader() | scb
$global:authResultARM.CreateAuthorizationHeader() | scb

This is what the top of Postman should look like:

2016-09-08_1435

Azure PowerShell

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: