PowerShell one-liner to easily use Azure VM Metadata Service

Have you heard about the Azure Instance Metadata Service?

When I implemented my blog in Azure I used a handy PowerShell “one-liner” to easily query specific information about the VM I was currently logged into.
The code uses the Metadata Service URL scheme do “drill” into the Data Categories.

So here is the code:

You can also create a function which gives a much easier flow of repetitive usage:


Note: During the creation of this blog I experimented with different instance types: virtual machines, containers, App Services. But I ended up using App Service for Containers and it mostly seems to work great.




Header photo by Rodger_Evans