Skip to content

Instantly share code, notes, and snippets.

@nordineb
Last active Sep 20, 2018
Embed
What would you like to do?
Azure Instance Metadata service
# Get all metadata
curl -H Metadata:true "http://169.254.169.254/metadata/instance?api-version=2017-04-02"
# Get all network metadata
curl -H Metadata:true "http://169.254.169.254/metadata/instance/network?api-version=2017-04-02"
# Get public ip only
curl -H Metadata:true "http://169.254.169.254/metadata/instance/network/interface/0/ipv4/ipAddress/0/publicIpAddress?api-version=2017-04-02&format=text"
#unique VM id
curl -H Metadata:true "http://169.254.169.254/metadata/instance/compute/vmId?api-version=2017-04-02&format=text"
Invoke-RestMethod -Headers @{"Metadata"="true"} -URI http://169.254.169.254/metadata/instance?api-version=2017-04-02 -Method get
Invoke-RestMethod -Headers @{"Metadata"="true"} -URI http://169.254.169.254/metadata/instance/network?api-version=2017-04-02 -Method get
@nordineb

This comment has been minimized.

Copy link
Owner Author

@nordineb nordineb commented Oct 11, 2017

The following data categories are available through the Instance Metadata Service:

Data Description
location Azure Region the VM is running in
name Name of the VM
offer Offer information for the VM image. This value is only present for images deployed from Azure image gallery.
publisher Publisher of the VM image
sku Specific SKU for the VM image
version Version of the VM image
osType Linux or Windows
platformUpdateDomain Update domain the VM is running in
platformFaultDomain Fault domain the VM is running in
vmId Unique identifier for the VM
vmSize VM size
ipv4/privateIpAddress Local IPv4 address of the VM
ipv4/publicIpAddress Public IPv4 address of the VM
subnet/address Subnet address of the VM
subnet/prefix Subnet prefix, example 24
ipv6/ipAddress Local IPv6 address of the VM
macAddress VM mac address
scheduledevents Currently in Public Preview See scheduledevents
@nordineb

This comment has been minimized.

Copy link
Owner Author

@nordineb nordineb commented Oct 11, 2017

@nordineb

This comment has been minimized.

Copy link
Owner Author

@nordineb nordineb commented Oct 11, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment