Skip to content

Instantly share code, notes, and snippets.

@nordineb
Last active September 20, 2018 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nordineb/01d69b63d2daf01e61b116bee607c6b8 to your computer and use it in GitHub Desktop.
Save nordineb/01d69b63d2daf01e61b116bee607c6b8 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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
Copy link
Author

@nordineb
Copy link
Author

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