Query Details
// Count of Company owned Devices that are Compliant or Not compliant IntuneDeviceComplianceOrg | where todatetime(LastContact) > ago(30d) | where ComplianceState == "Not compliant" // Change to "Compliant" if you want to count only Compliant Devices | where OwnerType == "Company" | summarize arg_max(TimeGenerated, *) by DeviceName | project ComplianceState, DeviceName, LastContact | summarize count(DeviceName) // Create a List with all devices: IntuneDeviceComplianceOrg | where todatetime(LastContact) > ago(30d) | where ComplianceState == "Not compliant" // Change to "Compliant" if you want to count only Compliant Devices | where OwnerType == "Company" | summarize arg_max(TimeGenerated, *) by DeviceName | project ComplianceState, DeviceName, LastContact, OS
This query is doing two main things:
It's counting the number of company-owned devices that are either compliant or not compliant, based on their last contact within the past 30 days. The compliance state can be changed to either "Compliant" or "Not compliant" depending on what you want to count.
It's creating a list of all these devices, showing their compliance state, device name, last contact, and operating system. Again, the compliance state can be changed to either "Compliant" or "Not compliant" depending on what you want to list.

Ugur Koc
Released: July 21, 2022
Tables
Keywords
Operators