top of page
Writer's pictureGeorge Lin

Query Azure VM Metadata Through IMDS


First, check out the most recent version of API:

Invoke-RestMethod -Headers @{"Metadata"="true"} -Method Get -NoProxy -Uri "HTTP://169.254.169.254/metadata/versions" | Select-Object -ExpandProperty apiVersions

Task 1: Check VM name, location, resourceGroupName, licenseType, offer, osType, version, sku, subscriptionId, vmSize, zone:

Invoke-RestMethod -Headers @{"Metadata"="true"} -Method Get -NoProxy -Uri "HTTP://169.254.169.254/metadata/instance/compute?api-version=2021-05-01"|Select-Object name, resourceGroupName, location, licenseType, offer, osType, version, sku, subscriptionId, vmSize, zone


Task 2: Check the OS image used to deploy the VM:

Invoke-RestMethod -Headers @{"Metadata"="true"} -Method Get -NoProxy -Uri "HTTP://169.254.169.254/metadata/instance/compute/storageProfile/imageReference?api-version=2021-05-01"

Task 3: Check VM OS disk information:

Invoke-RestMethod -Headers @{"Metadata"="true"} -Method Get -NoProxy -Uri "HTTP://169.254.169.254/metadata/instance/compute/storageProfile/osDisk?api-version=2021-05-01"|Select-Object -ExpandProperty managedDisk name,osType,diskSizeGB,caching,writeAccelerationEnabled|Select-Object -ExcludeProperty id

Task 4: Check VM data disk information:

 Invoke-RestMethod -Headers @{"Metadata"="true"} -Method GET -NoProxy -Uri "http://169.254.169.254/metadata/instance/compute/storageProfile/dataDisks?api-version=2021-02-01" | Select-Object -ExcludeProperty Item | Select-Object -ExpandProperty SyncRoot | Select-Object -ExpandProperty managedDisk name,lun,diskSizeGB,caching,writeAcceleratorEnabled | Select-Object -ExcludeProperty id | Format-Table

Task 5: Check VM computer name, administrator user name and password authentication status:
Invoke-RestMethod -Headers @{"Metadata"="true"} -Method Get -NoProxy -Uri "HTTP://169.254.169.254/metadata/instance/compute/osProfile?api-version=2021-05-01"

Task 6: Check Azure resource tags attached to the VM:
Invoke-RestMethod -Headers @{"Metadata"="true"} -Method Get -NoProxy -Uri "HTTP://169.254.169.254/metadata/instance/compute/tagsList?api-version=2021-05-01"

Task 7: Check VM network interface(#0) MAC address and IPV4 address:

Invoke-RestMethod -Headers @{"Metadata"="true"} -Method Get -NoProxy -Uri "HTTP://169.254.169.254/metadata/instance/network/interface/0?api-version=2021-05-01" | Select-Object -ExpandProperty ipv4 macAddress | Select-Object -ExpandProperty ipAddress macAddress
T
ask 8: Check VM subnet information:
 Invoke-RestMethod -Headers @{"Metadata"="true"} -Method Get -NoProxy -Uri "HTTP://169.254.169.254/metadata/instance/network/interface/0?api-version=2021-05-01" | Select-Object -ExpandProperty ipv4 | Select-Object -ExpandProperty subnet

Task 9: Get VM attested data:
Invoke-RestMethod -Headers @{"Metadata"="true"} -Method Get -NoProxy -Uri "HTTP://169.254.169.254/metadata/attested/document?api-version=2021-05-01" | fl

Task 10: Check the inbound rule information of VM's load balancer :
Invoke-RestMethod -Headers @{"Metadata"="true"} -Method GET -NoProxy -Uri "http://169.254.169.254/metadata/loadbalancer?api-version=2021-02-01" | Select-Object -ExpandProperty loadbalancer | Select-Object -ExpandProperty inboundRules

Task 11: Acquire an access token on the VM that has managed identity:
Invoke-WebRequest -Uri 'http://169.254.169.254/metadata/identity/oauth2/token?api-version=2021-05-01&resource=https%3A%2F%2Fmanagement.azure.com%2F' -Headers @{Metadata="true"} | Select-Object -ExpandProperty Content |  ConvertFrom-Json | Select-Object access_token

Task 12: Check the scheduled events on the VM
Invoke-RestMethod -Headers @{"Metadata"="true"} -Method GET -NoProxy -Uri "http://169.254.169.254/metadata/scheduledevents?api-version=2020-07-01"

0 comments

Comments


bottom of page