Use PowerShell to use the Azure Resource Manager (ARM) API

In the code below I am using PowerShell to access and use the Azure Resource Manager (ARM) API. It might be very uncommon to use PowerShell for this purpose because there is already an Azure RM PowerShell module.

But why would you need to use PowerShell to access the Azure RM API?

There are two reasons why you might need it:

  • Some Azure services are just released and there comes no PowerShell Cmdlets for them immediately. However there are almost always API documentations available for them which you can use.
  • Sometimes there are PowerShell Cmdlets for certain Azure services but if you want to do even more specific stuff you cannot find any commands and that is a pain. The code below is a clear example.

What does the code below do?

In the code below I first create a Service Principal (lines 14 to 19 – which can be removed from the script – it is just for demonstration) and then use it to request a token. I then use this token to make changes to a Docker Swarm cluster agent profile (lines 61 to 67). This was something I could not do using the Azure RM PowerShell Cmdlets which is why I am using the API:

 

 

Leave a Reply

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

%d bloggers like this: