Skip to content
Best Guide to Run Intune Device Query with Microsoft Graph API

Best Guide to Run Intune Device Query with Microsoft Graph API

Written By Sujin Nelladath
Last Updated April 17, 2024
Posted In Intune
SHARE

This post will show how to run the Intune Device Query with Microsoft Graph API. The present discourse endeavours to elucidate the functionality of the Graph API when utilizing the Intune device query. The exposition shall comprehensively explain the aforesaid concepts in clear, concise, and error-free language.

The Device Query feature in the Intune service is designed to facilitate efficient and streamlined device management and information retrieval. You must select the device from the Intune portal and then run the Kusto Query Language (KQL) query to use it.

The Device Query reports are available in real-time and can be retrieved directly. The output can be utilized to respond to security threats, troubleshoot the device, and make informed business decisions. If your license does not include Microsoft Intune Advanced Analytics, the Device Query option will not be available in your tenant. To access the features of Microsoft Intune Advanced Analytics, you can utilize the Intune Advanced Analytics Add-on or Microsoft Intune Suite

What sets Device Query apart is its ability to encrypt all data queries and results, ensuring that all transmission is secure. This feature offers a significant advantage over other similar platforms as it guarantees the protection of sensitive data throughout the entire process. Device query only supports a subset of KQL operators.

Patch My PC

Overview of Microsoft Graph

Microsoft Graph is an API (Application programming interface) that provides a single endpoint for accessing data, intelligence, and insights from Microsoft 365 and other Microsoft Cloud services. It provides a single endpoint, https://graph.microsoft.com, that enables access to various data and insights in the Microsoft cloud, including Microsoft 365, Windows, and Enterprise Mobility + Security.

Run Intune Device Query with Microsoft Graph API Fig. 1
Run Intune Device Query with Microsoft Graph API Fig. 1

By using Microsoft Graph, developers can build intelligent applications that leverage the power of Microsoft 365 and other Microsoft services to enhance productivity and collaboration.

Microsoft Graph can be leveraged to create personalized experiences catering to individual users’ unique contexts, thereby increasing their productivity. It offers a robust suite of services for managing user and device identity, access, compliance, security and data access on the following Microsoft cloud services.

Run Device Query through the Intune Portal

Let’s learn how to use Device Query in the Intune portal and retrieve live data.

  • Sign in to the Microsoft Intune Admin portal.
  • Go to Devices > All devices
  • Select the Device that you’re interested in
  • On the right-hand side, click on Device query
Run Intune Device Query with Microsoft Graph API Fig. 2
Run Intune Device Query with Microsoft Graph API Fig. 2

Once you click on Device query, you will have the Properties table like BiosInfo.

Run Intune Device Query with Microsoft Graph API Fig. 3
Run Intune Device Query with Microsoft Graph API Fig. 3

Run Device Query with Microsoft Graph

Understanding how to automate actions using Microsoft Graph is crucial when introducing new features to Intune. For anyone who wants to experiment with Graph, utilizing the developer mode from a browser is highly recommended. This method allows for greater efficiency and precision in implementing Graph features.

  • Sign in to the Microsoft Intune Admin portal.
  • Go to Devices > All devices
  • Select the Device that you’re interested in
  • On the right-hand side, click on Device query
  • Type your query
  • Press F12 to open developer mode
Run Intune Device Query with Microsoft Graph API Fig. 4
Run Intune Device Query with Microsoft Graph API Fig. 4
  • Select the Network tab
  • Click on Run
  • Click on the Stop Recording button
  • You will be able to find two resources called createQuery
Run Intune Device Query with Microsoft Graph API Fig. 5
Run Intune Device Query with Microsoft Graph API Fig. 5

You will be able to see the Requested URL resource when you click on first createQuery. The requested URL is the valid url to run the query in Graph API.

Run Intune Device Query with Microsoft Graph API Fig. 6
Run Intune Device Query with Microsoft Graph API Fig. 6

You will be able to see the body to pass in Payload. Click on the Payload option to view the query.

Run Intune Device Query with Microsoft Graph API Fig. 7
Run Intune Device Query with Microsoft Graph API Fig. 7

This is the query that has been parsed in JSON format, as shown in the example.

{"query":"Qmlvc0luZm8NCnwgcHJvamVjdCBNYW51ZmFjdHVyZXIsIFJlbGVhc2VEYXRlVGltZSwgU2VyaWFsTnVtYmVyLCBTbUJpb3NWZXJzaW9u"}

NOTE! In this case, it is important to note that the request method used to execute the query is POST. This method is commonly used in web development to send data to a server to be processed.

I will use Graph Explorer, a handy browser-based tool for running your Graph calls. However, it does not support commands in batch and is a single-line command executor. API calls will be made by utilizing the Graph Explorer. When you go to Graph Explorer, you will get a webpage like the one below.

NOTE! You may need to log in to Graph Explorer using your credentials if it's your first time. 
Run Intune Device Query with Microsoft Graph API Fig. 8
Run Intune Device Query with Microsoft Graph API Fig. 8

You will receive the API output response below once you click the Run query button.

NOTE ! You may encounter a 403 Forbidden error after clicking the Run query button. This is a known issue that is awaiting a solution from Microsoft.

How to Decode a Base-64 encoded value

The scriptContent is a base-64 encoded value. Let’s decrypt it by pasting it into an online decoder. You can also use Visual Studio Code to decode base-64 encoded value. Let’s try it now..!

  • Open the Online decoder site
  • Type the base-64 encoded value that you want to decode.
  • Click on Decode
Run Intune Device Query with Microsoft Graph API Fig. 9
Run Intune Device Query with Microsoft Graph API Fig. 9

Thank you for your patience in reading this post. I look forward to seeing you in the next post. Keep supporting the HTMD Community.

We are on WhatsApp. To get the latest step-by-step guides and news updates, Join our Channel. Click hereHTMD WhatsApp.

Author

About the Author – Sujin Nelladath has over 10 years of experience in device management technologies and Automation solutions. He writes and shares his experiences with Microsoft device management technologies, Azure, and PowerShell automation.

Written by

Sujin Nelladath is a Microsoft Graph MVP with over 12 plus years of experience in Intune, SCCM and M365 Automation solutions, writes and shares his experiences with Microsoft device management technologies, Azure, DevOps and PowerShell automation.

Discussion · 1 comment

  1. What all permissions are required.
    If it showing me this
    Forbidden – 403 – 1087 ms. Either the signed-in user does not have sufficient privileges, or you need to consent to one of the permissions on the Modify permissions tab

Join the discussion

Your email address will not be published. Required fields are marked *

Related guides

Intune

Simplify Windows Devices to Run Only the Required Applications using Intune

Key Takeaways Hey, let’s learn about Simplify Windows Devices to Run Only the Required Applications using Intune. This policy lets administrators replace the default windows shell with a custom or lightweight shell. it improves performance by using system resources and is useful for devices that run a dedicated application. If the policy is disabled or […]

AC Anoop C Nair 8 min read
Intune

Enhance macOS Compliance with Custom Security and Compliance Checks to Improve Device Security using Microsoft Intune

Key Takeaways In this post we are discussing about Enhance macOS Compliance with Custom Security and Compliance Checks to Improve Device Security using Microsoft Intune. Microsoft has announced the general availability of Custom Compliance Settings for macOS in Microsoft Intune. The feature helps organizations strengthen security controls while supporting many types of macOS management scenarios. […]

AC Anoop C Nair 4 min read
Intune

Manage Samsung Galaxy Firmware Versions to Improve Security and Compliance using Microsoft Intune

Key Takeaways In this post we are discussing Manage Samsung Galaxy Firmware Versions to Improve Security and Compliance using Microsoft Intune. Microsoft Intune has received a new update that expands firmware management capabilities for Samsung Galaxy devices through Firmware Versionsintegration. This enhancement gives IT administrators more control over firmware and operating system updates, helping them […]

AC Anoop C Nair 4 min read
Intune

MS Intune Adds Windows Registry Data Collection to Device Inventory for Single Values All Key Values and Subkeys

Key Takeaways Microsoft Intune 2607 introduces Windows Registry Data collection in Device Inventory, allowing IT admins to verify actual device configurations without relying on custom discovery or remediation scripts. Using the Properties Catalog, admins can collect registry information through Single Value, All Values Under a Key (Non-Recursive), or Same Value Across Subkeys. MS Intune Adds […]

AC Anoop C Nair 5 min read