Tutorial: How to retrieve Azure VM instance metadata without having subscription access

Posted by
Estimated Reading Time: 1 minute

Did you know you can leverage the Azure Instance Metadata Service to retrieve instance-specific details about your Azure VM? It provides information like the SKU, network configuration and tags.

Go ahead and try it out on an Azure VM using PowerShell:

Invoke-RestMethod -Headers @{"Metadata"="true"} -Uri ""

This will return all instance-specific details scoped to the compute node as shown in the example above.

You can also remove the compute node from the URI, which will return all of the instance details from top-level, including the attached NIC(‘s).

Invoke-RestMethod -Headers @{"Metadata"="true"} -Uri ""

Another tip is to convert the output to JSON which would make it more readable:

Invoke-RestMethod -Headers @{"Metadata"="true"} -Uri "" | ConvertTo-Json -Depth 99

Example output

  "compute": {
    "azEnvironment": "AZUREPUBLICCLOUD",
    "location": "centralus",
    "name": "negasonic",
    "offer": "lampstack",
    "osType": "Linux",
    "placementGroupId": "",
    "plan": {
        "name": "5-6",
        "product": "lampstack",
        "publisher": "bitnami"
    "platformFaultDomain": "0",
    "platformUpdateDomain": "0",
    "provider": "Microsoft.Compute",
    "publicKeys": [],
    "publisher": "bitnami",
    "resourceGroupName": "myrg",
    "sku": "5-6",
    "subscriptionId": "xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx",
    "tags": "Department:IT;Environment:Prod;Role:WorkerRole",
    "version": "7.1.1902271506",
    "vmId": "13f56399-bd52-4150-9748-7190aae1ff21",
    "vmScaleSetName": "",
    "vmSize": "Standard_A1_v2",
    "zone": "1"
  "network": {
    "interface": [
        "ipv4": {
          "ipAddress": [
              "privateIpAddress": "",
              "publicIpAddress": "X.X.X.X"
          "subnet": [
              "address": "",
              "prefix": "24"
        "ipv6": {
          "ipAddress": []
        "macAddress": "000D3A36DDED"

Fore more information, please check:


Leave a Reply

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