Open In App

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

Last Updated : 13 Apr, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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 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 User Name of a Specific select VM.

Sample Output:


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads