Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Microsoft Azure – Graph Query to Get Properties of Azure VM Resource

  • Last Updated : 29 Dec, 2021

The following are the Azure Resource Graph Queries where we will be used to fetch the static JSON data using azure KQL Queries. You can run the below queries in Azure Resource Graph Explorer in Azure Portal to fetch the results based on Query.

Example 1:

To get the complete properties of Azure VMs –

resources
| where type == "microsoft.compute/virtualmachines"

This query returns the details and the total number of results.

  • id
  • name
  • type
  • tenantId
  • kind
  • location
  • resourceGroup
  • subscriptionId
  • managedBy
  • sku
  • plan
  • properties
  • tags
  • identity
  • zones
  • extendedLocation

Sample Output:

Example 2: To get the properties of Azure VM Name, Resource Group, VM Admin User Name of all the VMs from the select scope.

resources
| where type == "microsoft.compute/virtualmachines"
| project name,resourceGroup,AdminUserName=tostring(properties.osProfile.adminUsername)

This query returns the output of VM Computer Name, Resource Group, and VM Admin Admin User Name of all the Azure VMs from the scope selected.

Sample Output:

Example 3: To get the properties of Azure VM Name, Resource Group, VM Admin User Name of a specific Azure VM from the select scope.

resources
| where type == "microsoft.compute/virtualmachines"
| where name == "CloudOpsVM"
| project name,resourceGroup,AdminUserName=tostring(properties.osProfile.adminUsername)

this query returns the output of VM Computer Name, Resource Group, and VM Admin Admin User Name of a Specific select VM.

Sample Output:

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!