brianfgonzalez

kusto

Apr 16th, 2026 (edited)
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.24 KB | None | 0 0
  1. // Kusto queries
  2. // if you have one you'd like to share add it as a comment and i will add it up top
  3.  
  4. // diff ways to filter time
  5. | where env_time > ago(1d)
  6. | where env_time between (datetime(2026-02-25 00:09:54) .. datetime(2026-03-6 00:09:54))
  7.  
  8. // tenant id => accountid, asmu
  9. let cxTenantId = '';
  10. DeviceManagementProvider
  11. | where accountContextId == cxTenantId
  12. | project accountId, asmu=env_cloud_name
  13. | take 5
  14.  
  15. // device check-in logs
  16. let cxDeviceID = '';
  17. let cxAccountId = '';
  18. DeviceManagementProvider
  19. | where env_time > ago(1d)
  20. | where accountId == cxAccountId
  21. | where ActivityId == cxDeviceID
  22. | where isnotempty(message)
  23. | project env_time, message
  24.  
  25. // see enrollment related events
  26. let cxAccountId = '';
  27. let cxTenantId = '';
  28. DeviceLifecycle
  29. | where env_time >= ago(10d)
  30. | where accountId == cxAccountId or accountContextId == cxTenantId
  31. //| where TaskName contains "Fail"
  32. | project env_time, deviceId, userId, aadDeviceId, TaskName, details, scenarioType, cV
  33.  
  34. // 1. returns when the device first started talking and last
  35. let start = datetime(2026-08-20 19:20:00Z);
  36. let end = datetime(2026-08-20 19:55:00Z);
  37. let CxAadDeviceId = '';
  38. let cxDeviceID = '';
  39. cluster("intune.kusto.windows.net").database("Intune").IntuneEvent
  40. | where env_time between (start .. end)
  41. | where env_cloud_environment == "PE"
  42. | where cxDeviceID == intuneDeviceId or ActivityId == CxAadDeviceId
  43. | summarize Count=count(), FirstSeen=min(env_time), LastSeen=max(env_time),
  44. SampleCV=take_any(cV)
  45. by ServiceName, ComponentName, EventUniqueName, TraceLevel
  46. | top 50 by Count desc
  47.  
  48. // 2. grab SampleCV and enter it into the query below
  49. let cxSampleCV = "fXkUz5Qcs0GRwcZKaNn8dA";
  50. cluster("intune.kusto.windows.net").database("Intune").IntuneEvent
  51. | where env_time between (
  52. datetime(2026-08-20 19:24:30Z) .. datetime(2026-08-20 19:26:00Z))
  53. | where cV startswith cxSampleCV
  54. | project env_time, env_cloud_name, ServiceName, ComponentName,
  55. EventUniqueName, TraceLevel, AccountId, ContextId, DeviceId,
  56. ActivityId, cV, ColMetadata, Col1, Col2, Col3, Message
  57. | order by env_time asc
  58. | take 200
  59.  
  60. // 3.
  61. let start = datetime(2026-08-20 19:20:00Z);
  62. let end = datetime(2026-08-20 19:55:00Z);
  63. let targetAsu = "AMSUA0401";
  64. let accountId = "b41d5774-a53c-4970-8733-cecfbb20e382";
  65. let tenantId = "9a307864-3e98-4f08-b90a-728b62cf32c5";
  66. cluster("intune.kusto.windows.net").database("Intune").IntuneEvent
  67. | where env_time between (start .. end)
  68. | where env_cloud_name == targetAsu
  69. | where AccountId == accountId or ContextId == tenantId
  70. | where EventUniqueName == "EspSlaIsDeviceSyncDone"
  71. | project env_time, ServiceName, ComponentName, EventUniqueName,
  72. TraceLevel, AccountId, ContextId, DeviceId, ActivityId, cV,
  73. ColMetadata, Col1, Col2, Col3, Message
  74. | order by env_time asc
  75. | take 100
  76.  
  77. // applicablilityState == Applicable means the device thinks the policy applies.
  78. // reportComplianceState is the key state column you’re after (e.g., Compliant, Noncompliant, etc.)
  79. let cxDeviceID = '';
  80. let cxPolicyId = '';
  81. DeviceManagementProvider
  82. | where env_time > ago(1d)
  83. | where TaskName == "DeviceManagementProviderCIReportDataEvent"
  84. | where deviceId == cxDeviceID
  85. | where policyId == cxPolicyId
  86. | where applicablilityState == "Applicable"
  87. | project env_time,
  88. deviceId,
  89. policyId,
  90. typeAndCategory,
  91. applicablilityState,
  92. reportComplianceState,
  93. errorCode,
  94. EventMessage
  95. | order by env_time desc
  96.  
  97. // looking for policy conflicts
  98. let cxDeviceID = '';
  99. let cxAccountId = '';
  100. IntuneEvent
  101. | where env_time > ago(3d)
  102. | where AccountId == cxAccountId
  103. | where ApplicationName startswith "DeviceCheckin"
  104. | where DeviceId == cxDeviceID
  105. | where Col5 != "NotApplicable"
  106. | where Col1 contains "conflict"
  107. | project env_time, Col1, Col2, Col3, Col4, ScenarioInstanceId
  108.  
  109. // see wipe or retire actions against a specific device
  110. let cxAccountID = "xxx";
  111. let cxDeviceID = "xxx";
  112. HttpSubsystem
  113. | where env_time >= ago(10d)
  114. | where accountId == cxAccountID
  115. | where url contains cxAccountID
  116. | where url contains "wipe" or url contains "retire"
  117. | where httpVerb == "POST" or httpVerb == "ACTION" or httpVerb == "DELETE"
  118. | project env_time, ActivityId, url, cVBase, statusCode, httpVerb
  119. | take 500
  120.  
  121. // IOS SECTION
  122. //To Know the Enrollment Type for iOS
  123. let cxASU = "xxx";//use FXPASU01 for GCC High environments
  124. let cxAccountID = "xxx";
  125. let cxDeviceID = "xxx";
  126. IntuneEvent
  127. | where env_time > ago(8d)
  128. | where SourceNamespace == "IntunePE" //IntuneFXP for GCC High
  129. //| where env_time > datetime(2025-04-12 01:00) and env_time < datetime(2025-04-13 23:59)
  130. //| where env_cloud_name == cxASU
  131. //| where AccountId == cxAccountID
  132. | where ActivityId == cxDeviceID
  133. | where Col1 has "EnrollmentType" or Col1 has "OSVersion:" //for iOS Shows multiple device Details, like OSversion, Model and other hardware details
  134. | project env_time, Col1, Col2, Col3, Col4, Col5, Col6,ActivityId, UserId, DeviceId,AccountId
  135.  
  136. //To get VPP token
  137. let cxIntuneASU = ""; //use FXPASU01 for GCC High Environments
  138. let cxIntuneAccountID = "";
  139. let cxIntuneVPPToken = "";
  140. IntuneEvent
  141. | where env_time > ago(2d)
  142. | where env_cloud_name == cxIntuneASU
  143. | where AccountId == cxIntuneAccountID // and PayLoadId == IntuneVPPToken
  144. | where ApplicationName == "AppleVPP"
  145. | where EventUniqueName == "ValidatingSToken"
  146. | project env_time,EventUniqueName,Message,CurrentState=Col3,TokenId=PayLoadId,TokenLocationId=Col5,TokenLocationName=Col4
  147.  
  148. // For iOS/iPadOS and macOS app deployment (LOB, App Store and VPP Apps)
  149. let cxDeviceID = "";
  150. let whatsappmess = "310633997";
  151. let oktaverify = "490179405" ;
  152. let jabber = "1487776871" ;
  153. let microsoftonedrive = "477537958" ;
  154. let google = "284815942" ; // https://apps.apple.com/us/app/id284815942
  155. IntuneEvent
  156. | where env_time > ago(21d)
  157. | where SourceNamespace == "IntunePE"//For GCC High Kusto comment this line out or use "IntuneFXP" SourceNamespace
  158. | where ActivityId == cxDeviceID
  159. | where EventUniqueName == "AppleAppSummary"
  160. | where Col1 contains microsoftonedrive
  161. | project env_time, Col1, Col2, Col3, Col4, Col5, Col6,ActivityId, UserId, DeviceId,AccountId,env_cloud_name,BuildVersion
  162. | sort by env_time
  163.  
  164. // User check-in MAM per user ID
  165. let UserID = '';
  166. let _endTime = datetime(2026-04-20T18:00:53Z);
  167. let _startTime = datetime(2026-04-20T17:00:53Z);
  168. AmsActivityForUser(['UserID'], start=['_startTime'], end=['_endTime'])
  169. | project env_time, ['type'], statusCode, AppId, Os, DeviceId, AppVersion, SdkVersion, ManagementLevel, AppFriendlyName, PolicyState, DeviceModel
  170.  
  171. // This query allows user to see policy status per device / per user
  172. DeviceManagementProvider
  173. | where env_time > ago(30d)
  174. | where ActivityId == 'xxxxxxxxxxxxxxxxxxxxxx'
  175. | where EventId == 5786
  176. | where applicablilityState == 'Applicable'
  177. | extend PolicyType = iff(tostring(split(typeAndCategory, ';')[1]) == 'None', 'GeneralConfiguration', iff(typeAndCategory == 'Application;Application', 'MangedDeviceAppConfig', tostring(split(typeAndCategory, ';')[1])))
  178. | project env_time, tenantId, deviceId = ActivityId, PolicyName=name, PolicyType, ComplianceState=reportComplianceState, PolicyId = translate('_', '-', extract('_([a-z0-9_]{36})', 1, ['id'])), userId
  179.  
  180. // This query allows me to actively investigate SyncML 500 issues for the ongoing compliance issues and to feed data to the Product Group with that regard
  181. DmpLogs
  182. | where env_time > ago(7d)
  183. | where env_cloud_name == "AMSUB0101" // AMSU Here
  184. | where message startswith "New Session" or message contains "Discovery error: Status=Failed;" or message contains "Status.Data for get command not '200'"
  185. | where ActivityId == "deviceidhere" // DeviceId Here
  186. | project env_time, userId, scenarioInstanceId, message
  187.  
  188. // This query allows me to check for Compliance Patching of the corresponding Azure Objects from Intune
  189. let cxDeviceID = "xxx";
  190. GraphApiProxyLibrary
  191. | where env_time >= ago(3d)
  192. | where url contains cxDeviceID
  193.  
  194. // This query checks all Non-Compliance against a singular device
  195. IntuneEvent
  196. | where env_time > ago(3d)
  197. | where env_cloud_name == "AMSUB0501"
  198. | where ServiceName == "StatelessComplianceCalculationService"
  199. | where EventUniqueName == "ComplianceDetail-GetComplianceDetailsForDeviceAction-FinalResult"
  200. | where Col1 contains "DEVICEIDHERE" // DeviceId
  201. | project env_time, ServiceName, ComponentName, EventUniqueName, ColMetadata, Col1, Col2, Col3, Col4, Col5, Col6, Message, cV, ScenarioType, TraceLevel, ActivityId
  202.  
  203. // This query check the tenant for a specific Non-compliant event; I.e Firewall_Enabled
  204. let cxAccountID = "xxx";
  205. IntuneEvent // CHECK THIS FOR FIREWALL ISSUES AGAINST A TENANT (SYNCML500)
  206. | where env_cloud_name == "AMSUB0201"
  207. | where env_time > ago(12h)
  208. | where ServiceName == "StatelessComplianceCalculationService"
  209. | where EventUniqueName == "ComplianceDetail-GetComplianceDetailsForDeviceAction-FinalResult"
  210. | where Col1 contains cxAccountID
  211. | project env_time, ServiceName, ComponentName, EventUniqueName, ColMetadata, Col1, Col2, Col3, Col4, Col5, Col6, Message, cV, ScenarioType, TraceLevel, ActivityId, env_cloud_name
  212. | summarize argmax(env_time, Col5) by Col1
  213. | project max_env_time_Col5, Col1
  214. | extend ComplianceState = extract("ComplianceState:(.*?);", 1, max_env_time_Col5)
  215. | extend ComplianceReasons = extractall("SettingId:(.*?);", max_env_time_Col5)
  216. |where ComplianceReasons contains "Firewall_Enabled" // CHANGE THIS TO THE COMPLIANCE FAILURE YOU'RE SEEING AGAINST A TENANT
  217. //| where ComplianceReasons contains "DefenderEnabled"
  218. | summarize count() by ComplianceState , tostring(ComplianceReasons)
  219. | order by count_
  220.  
  221. // AUTOPILOT RELATED
  222. //////////////////////////////////////
  223.  
  224. // Find device registrations
  225. let cxSerialNumber = "xxx";
  226. IntuneEvent
  227. | where env_time > ago(180d)
  228. | where ServiceName == "WindowsAutopilotWorkItemProcessorService"
  229. | where EventUniqueName in ("DeviceRegistered","DeviceInBatchProcessed","HardwareHashResolved")
  230. | where Col1 has cxSerialNumber
  231. | project env_time, EventUniqueName, Col1
  232. | order by env_time asc
  233.  
  234. // TO investigate the AP Fix Pending / Attention Scenario Issues, you will need to run 2 Kusto queries and compare.
  235. let cxAccountID = "xxx";
  236. ZTDDevice_Snapshot
  237. | where ZTDDeviceRemediationStateLastModifiedDateTime > ago(30d)
  238. | where AccountId == cxAccountID
  239. | where ZTDDeviceRemediationState == '1' // Change to 2 for Fix Pending, or 3 for Attention required. 1 obviously means normal
  240.  
  241. let cxDeviceID = "xxx";
  242. Device_Snapshot
  243. | where * has cxDeviceID
  244.  
  245. // Once you have ran the first query, scroll right to the end and look for the column "ZTDDeviceRemediationStateLastModifiedDateTime"
  246. // Take down the times and then run
  247. IntuneEvent
  248. | where env_time > ago(30d) // Insert time range
  249. | where ApplicationName == "WindowsAutopilot"
  250. | where EventUniqueName == 'ProfileDownloadBlocked'
  251. //| where Col1 has 'isHardwareMatch: True'
  252. | where Col1 has 'CONTEXTIDHERE' // CONTEXT Tenant ID
  253. | project env_time, env_cloud_name, env_cloud_role, ComponentName, EventUniqueName,DeviceId,ExceptionDetails = Message, EventDetails = Col1, env_seqNum, ActivityId
  254.  
  255. // Find support ticket ID, if restricted, or rCRI from ICM number
  256. // If IsCustomerSupportEngagement AND IsRestricted == TRUE, then it is an rCRI
  257. // If IsCustomerSupportEngagement == TRUE and IsRestricted == FALSE then normal CRI
  258. // If IsCustomerSupportEngagement == FALSE and IsRestricted == TRUE then a 'restricted incident'
  259. cluster('icmcluster.kusto.windows.net').database('IcmDataWarehouse').IncidentsSnapshotV2
  260. //| where OwningTenantName == "Microsoft Intune"
  261. | where SupportTicketId startswith "2603030040001811"
  262. | project IncidentId, CreateDate, ModifiedDate, Status, IsCustomerSupportEngagement, IsRestricted, SupportTicketId, Title, SourceCreatedBy, OriginatingTenantName, OwningTeamName, OwningTenantName
  263. //| take 1000
  264.  
  265. // RBAC related - relies on har info - bwatt
  266. //WOMBOCOMBO - OHBABYATRIPLE
  267. let _creationTime = datetime(2026-04-30T21:21:54); // paste Date: value from HAR. Kusto will parse as datetime
  268. let _clientRequestID = "xxx" ; // client-request-id: from HAR
  269. let _start = datetime_add('minute', -3, _creationTime);
  270. let _end = datetime_add('minute', 3, _creationTime);
  271. let RBAC = union IntuneEvent, SecuritySubsystem, HttpSubsystem;
  272. RBAC
  273. | where env_time between (_start .. _end )
  274. | where SourceNamespace == "IntunePE" //IntuneFXP for GCCH
  275. | where ActivityId == _clientRequestID
  276. | where (Message startswith "Microsoft." or isnotempty(exception))
  277. or (TaskName == 'EffectiveUserPermissionAuthorizationValidationFailureEvent')
  278. or (isnotempty(httpVerb))
  279. | project env_time, TaskName, EventUniqueName, message = Message, exception ,callerMethod, ColMetadata, Col1,Col2, Col3, userId = UserId, deviceId = DeviceId, tenantId = AccountId, requiredPermission, FunctionName, ApplicationName, ComponentName, httpVerb, statusCode_long, url, cVBase, ActivityId, scenarioType, collectionName
  280. | sort by env_time asc
  281.  
  282. // AUTOPILOT
  283. // RUN in a365
  284. // shows if a device has an assigned deployment profile
  285. // IntuneProfileIdentifier => GUID of AP deployment profile assigned
  286. // IntuneProfileAssignmentStatus => 0/1 shows if profile is assigned
  287. let currentTenantId = '';
  288. let DeviceID = '';
  289. ZTDDevice_Snapshot_AMSUA0401 //update ASU
  290. | where AccountId == currentTenantId
  291. | where ZTDRegistrationId == DeviceID or DeviceDataStoreAzureADDeviceId == DeviceID or AADObjectId == DeviceID or CreateIntuneDeviceId == DeviceID
  292. | project ZTDCreatedTime, ZTDRegistrationId, IntuneProfileIdentifier, IntuneProfileAssignmentStatus, ZTDOemManufacturer, ZTDModelName, IsDeleted, DeviceDeletionStatus, DeviceId, DeviceDataStoreAzureADDeviceId, AADObjectId
  293.  
  294. // grab correlationvector from registry
  295. // in MdmDiagReport_RegistryDump.reg in mdmdiag.cab
  296. //[HKEY_LOCAL_MACHINE\software\microsoft\provisioning\AutopilotPolicy]
  297. //"AutopilotUpdateTimeout"=DWORD:001b7740
  298. //"AutopilotCorrelationVector"="I/ZkJltpUkqYZUir.0"
  299. //"AutopilotMode"=DWORD:00000000
  300. // in my case it was confirming a "RequestErrorCode: 807 - ZtdDeviceIsNotRegistered" was being tossed
  301. let apsCv = 'ZkJltpUkqYZUir.0';
  302. let downloadDateTime = datetime('2026-05-08');
  303. let timeBeforeMinutes = 600;
  304. let timeAfterMinutes = 600;
  305. let startTime = datetime_add('minute', 0 - timeBeforeMinutes, downloadDateTime);
  306. let endTime = datetime_add('minute', timeAfterMinutes, downloadDateTime);
  307. cluster('intune.kusto.windows.net').database('Intune').IntuneEvent
  308. | where env_time between(startTime..endTime)
  309. | where ApplicationName == 'WindowsAutopilot'
  310. | where env_cloud_environment == 'PE'
  311. | where Col2 contains apsCv
  312. | order by env_time desc
  313. | project env_time, ActivityId, ServiceName, EventUniqueName, ColMetadata, Col1, Col2, Col3, FunctionName, FileName, LineNumber
  314.  
  315. // VPP app license troubleshooting
  316. let IntuneASU = "";
  317. let IntuneVPPToken = "";
  318. let IntuneDeviceID = "";
  319. let SerialNumber = "";
  320. let AdamId = "544007664"; // YouTube (swap per app)
  321. let AppBundleId = "com.google.ios.youtube"; // must match AdamId
  322. let tStart = datetime(2026-06-16 20:00);
  323. let tEnd = datetime(2026-06-19 20:35);
  324. // 1) Intune -> Apple: license association request (AppleVPP service)
  325. let s1 = IntuneEvent
  326. | where env_time between (tStart..tEnd) and env_cloud_name == IntuneASU
  327. | where EventUniqueName == "ManageLicensesFinished" and Col1 == IntuneVPPToken
  328. | where Col4 == SerialNumber and Col3 has AdamId
  329. | project env_time, Seq=1, Source="1 Intune Associate", Action=tostring(Col2), Detail=strcat("adamIds=", tostring(Col3));
  330. // 2) Apple result: raw notification (type + result)
  331. let s2 = IntuneEvent
  332. | where env_time between (tStart..tEnd) and env_cloud_name == IntuneASU
  333. | where EventUniqueName == "RawAppleNotification" and Col3 has SerialNumber and Col3 has AdamId
  334. | extend n = parse_json(tostring(Col3))
  335. | project env_time, Seq=2, Source="2 Apple Result",
  336. Action=strcat(tostring(n.notification.type)," / ",tostring(n.notification.result)),
  337. Detail=strcat("adamId=", tostring(n.notification.assignments[0].adamId));
  338. // 3) Device check-in: install command issue + result (joined on CmdUUID)
  339. let inst = DeviceManagementProvider
  340. | where env_time between (tStart..tEnd) and env_cloud_name == IntuneASU and ActivityId == IntuneDeviceID
  341. | where commandType == "InstallApplication" and subType == "DeepLink (VPP)"
  342. | extend CmdUUID = extract(@"CmdUUID:'([^']+)'",1,message),
  343. BundleId = extract(@"identifier ([^ ]+) with CmdUUID",1,message);
  344. let s3 = inst | where EventId==5782 | project CmdUUID, BundleId, env_time
  345. | join kind=inner (inst | where EventId==5783 | project CmdUUID, rt=env_time, commandResultStatus, errorCode) on CmdUUID
  346. | where BundleId == AppBundleId
  347. | project env_time=rt, Seq=3, Source="3 Device InstallApp",
  348. Action=commandResultStatus, Detail=strcat("errorCode=", errorCode);
  349. // 4a) AppleVPP sync: EXACT per-device license removed (token / asset / target-serial)
  350. let s4 = IntuneEvent
  351. | where env_time between (tStart..tEnd) and env_cloud_name == IntuneASU
  352. | where EventUniqueName == "DeletedCosmosEntityBatch"
  353. | where (Col1 == IntuneVPPToken or PayLoadId == IntuneVPPToken or Col3 has IntuneVPPToken)
  354. | where Col3 has AdamId and Col3 has SerialNumber
  355. | mv-expand ent = parse_json(tostring(Col3)) to typeof(string)
  356. | extend target = extract(@"TargetId='([^']+)'",1,ent), asset = extract(@"AdamId='([^']+)'",1,ent)
  357. | where target == SerialNumber and asset == AdamId
  358. | summarize env_time = min(env_time) by target, asset
  359. | project env_time, Seq=4, Source="4 AppleVPP LicenseSync",
  360. Action="REMOVE license",
  361. Detail=strcat("token=", IntuneVPPToken, " asset=", asset, " target(serial)=", target);
  362. // 4b) (context) the reconciliation summary line with the delete count
  363. let s4b = IntuneEvent
  364. | where env_time between (tStart..tEnd) and env_cloud_name == IntuneASU
  365. | where EventUniqueName == "LicenseUpdateStatus" and (Col1 == IntuneVPPToken or PayLoadId == IntuneVPPToken)
  366. | where Col2 == AdamId and Col3 == "DeviceLicenseDto"
  367. | project env_time, Seq=5, Source="4 AppleVPP LicenseSync (count)", Action="LicenseUpdate", Detail=tostring(Message);
  368. union s1, s2, s3, s4, s4b
  369. | sort by env_time asc, Seq asc
  370. | project env_time, Source, Action, Detail
  371.  
  372.  
Advertisement
Add Comment
Please, Sign In to add comment