{"id":217,"date":"2025-02-12T19:54:41","date_gmt":"2025-02-12T18:54:41","guid":{"rendered":"https:\/\/digitalmaterial.ch\/blog\/?p=217"},"modified":"2026-03-25T15:29:19","modified_gmt":"2026-03-25T14:29:19","slug":"custom-device-inventory-with-intune","status":"publish","type":"post","link":"https:\/\/digitalmaterial.ch\/blog\/custom-device-inventory-with-intune\/","title":{"rendered":"Custom Device-Inventory with Intune"},"content":{"rendered":"\n<p>While Intune stores some information about the devices it manages, at some point you will need some additional data. And with some extra steps, it is possible to fetch a custom inventory from the devices.<\/p>\n\n\n\n<p>In this blog, we are going to fetch the Windows 11 readiness of all managed devices. This is done with the following three steps:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Prepare the Script<\/li>\n\n\n\n<li>Deploy the Script<\/li>\n\n\n\n<li>Fetch the results<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Prepare the Script<\/h2>\n\n\n\n<p>First thing we need to have is a PowerShell Script that returns some JSON-Data. This is crucial, as we need to parse the data that is returned from the script. So in this use case, we grab the Hardware Readiness Script directly from Microsoft: <a href=\"https:\/\/aka.ms\/HWReadinessScript\">https:\/\/aka.ms\/HWReadinessScript<\/a><\/p>\n\n\n\n<p>If we run the script on our local machine with Administrative privileges, we get the following data:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">JSON<\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>{\n    \"returnCode\": 0,\n    \"returnReason\": \"\",\n    \"logging\": \"Storage: OSDiskSize=476GB. PASS; Memory: System_Memory=16GB. PASS; TPM: TPMVersion=2.0, 0, 1.38. PASS; Processor: {AddressWidth=64; MaxClockSpeed=2419; NumberOfLogicalCores=8; Manufacturer=GenuineIntel; Caption=Intel64 Family 6 Model 140 Stepping 1; }. PASS; SecureBoot: Capable. PASS; \",\n    \"returnResult\": \"CAPABLE\"\n}<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D4D4D4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">&quot;returnCode&quot;<\/span><span style=\"color: #D4D4D4\">: <\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">&quot;returnReason&quot;<\/span><span style=\"color: #D4D4D4\">: <\/span><span style=\"color: #CE9178\">&quot;&quot;<\/span><span style=\"color: #D4D4D4\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">&quot;logging&quot;<\/span><span style=\"color: #D4D4D4\">: <\/span><span style=\"color: #CE9178\">&quot;Storage: OSDiskSize=476GB. PASS; Memory: System_Memory=16GB. PASS; TPM: TPMVersion=2.0, 0, 1.38. PASS; Processor: {AddressWidth=64; MaxClockSpeed=2419; NumberOfLogicalCores=8; Manufacturer=GenuineIntel; Caption=Intel64 Family 6 Model 140 Stepping 1; }. PASS; SecureBoot: Capable. PASS; &quot;<\/span><span style=\"color: #D4D4D4\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">&quot;returnResult&quot;<\/span><span style=\"color: #D4D4D4\">: <\/span><span style=\"color: #CE9178\">&quot;CAPABLE&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This looks good so far and returns some JSON-Data already. But to identify the devices, we add the following lines to the script to get the Hostname and Serial-Number in the output:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">PowerShell<\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>$outObject.Hostname = $env:computername\n$outObject.SerialNumber = (Get-WmiObject -class win32_bios).SerialNumber\n\n$outObject | ConvertTo-Json -Compress<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #9CDCFE\">$outObject<\/span><span style=\"color: #DCDCAA\">.Hostname<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #9CDCFE\">$env:computername<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">$outObject<\/span><span style=\"color: #DCDCAA\">.SerialNumber<\/span><span style=\"color: #D4D4D4\"> = (<\/span><span style=\"color: #DCDCAA\">Get-WmiObject<\/span><span style=\"color: #D4D4D4\"> -class win32_bios).SerialNumber<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">$outObject<\/span><span style=\"color: #D4D4D4\"> | <\/span><span style=\"color: #DCDCAA\">ConvertTo-Json<\/span><span style=\"color: #D4D4D4\"> -Compress<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This returns the following output. So now, we can identify the device and see if it is capable or not.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">JSON<\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>{\n    \"returnCode\": 0,\n    \"returnReason\": \"\",\n    \"logging\": \"Storage: OSDiskSize=476GB. PASS; Memory: System_Memory=16GB. PASS; TPM: TPMVersion=2.0, 0, 1.38. PASS; Processor: {AddressWidth=64; MaxClockSpeed=2419; NumberOfLogicalCores=8; Manufacturer=GenuineIntel; Caption=Intel64 Family 6 Model 140 Stepping 1; }. PASS; SecureBoot: Capable. PASS; \",\n    \"returnResult\": \"CAPABLE\",\n    \"Hostname\": \"DGMT-64915\",\n    \"SerialNumber\":\"CNDABCDEFG\"\n}<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D4D4D4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">&quot;returnCode&quot;<\/span><span style=\"color: #D4D4D4\">: <\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">&quot;returnReason&quot;<\/span><span style=\"color: #D4D4D4\">: <\/span><span style=\"color: #CE9178\">&quot;&quot;<\/span><span style=\"color: #D4D4D4\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">&quot;logging&quot;<\/span><span style=\"color: #D4D4D4\">: <\/span><span style=\"color: #CE9178\">&quot;Storage: OSDiskSize=476GB. PASS; Memory: System_Memory=16GB. PASS; TPM: TPMVersion=2.0, 0, 1.38. PASS; Processor: {AddressWidth=64; MaxClockSpeed=2419; NumberOfLogicalCores=8; Manufacturer=GenuineIntel; Caption=Intel64 Family 6 Model 140 Stepping 1; }. PASS; SecureBoot: Capable. PASS; &quot;<\/span><span style=\"color: #D4D4D4\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">&quot;returnResult&quot;<\/span><span style=\"color: #D4D4D4\">: <\/span><span style=\"color: #CE9178\">&quot;CAPABLE&quot;<\/span><span style=\"color: #D4D4D4\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">&quot;Hostname&quot;<\/span><span style=\"color: #D4D4D4\">: <\/span><span style=\"color: #CE9178\">&quot;DGMT-64915&quot;<\/span><span style=\"color: #D4D4D4\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">&quot;SerialNumber&quot;<\/span><span style=\"color: #D4D4D4\">:<\/span><span style=\"color: #CE9178\">&quot;CNDABCDEFG&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Deploy the Script<\/h2>\n\n\n\n<p>Now, we need to deploy the script to the Clients. We do this with a simple Platform-Script. No App or Remediation required. So we create a new script, add a sensible name, upload the script and make sure to <strong>not<\/strong> run it with the logged on credentials, as the script needs to be run with administrative privileges.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"784\" height=\"247\" src=\"https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2025\/02\/image-10.png\" alt=\"\" class=\"wp-image-542\" srcset=\"https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2025\/02\/image-10.png 784w, https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2025\/02\/image-10-300x95.png 300w, https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2025\/02\/image-10-768x242.png 768w\" sizes=\"auto, (max-width: 784px) 100vw, 784px\" \/><\/figure>\n\n\n\n<p>We can either deploy the script to all devices or just a group of devices. In this case it would make sense to create a group with Windows 10 devices, as we are not interested in the readiness of Windows 11 devices. You may use the following filter to create a dynamic group with Windows 10 devices:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">PowerShell<\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>(device.deviceOSVersion -startsWith \"10.0.1\")<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D4D4D4\">(device.deviceOSVersion -startsWith <\/span><span style=\"color: #CE9178\">&quot;10.0.1&quot;<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>After we have deployed the script, we wait. Intune evaluates the scripts only after quite a long period. Usually it makes sense to wait for the next reboot of the devices.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Fetch the results<\/h2>\n\n\n\n<p>After the script has been executed on the devices we can check for the results. This can be done in multiple ways, and we start with the simplest, the manual way.<\/p>\n\n\n\n<p>In the Intune-Portal we can open the Platform-Script, head over to User-Status and select a user. Right there in the Results-Column we can already see the JSON-Data that has been returned for that user.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"137\" src=\"https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2025\/02\/image-7-1024x137.png\" alt=\"\" class=\"wp-image-534\" srcset=\"https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2025\/02\/image-7-1024x137.png 1024w, https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2025\/02\/image-7-300x40.png 300w, https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2025\/02\/image-7-768x102.png 768w, https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2025\/02\/image-7-1536x205.png 1536w, https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2025\/02\/image-7.png 1589w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>But we do not want to check for every user manually, but automate this and return a list of all devices. At first we need to grab the ID of the script, which can be found in the URL:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"154\" src=\"https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2025\/02\/image-11-1024x154.png\" alt=\"\" class=\"wp-image-543\" srcset=\"https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2025\/02\/image-11-1024x154.png 1024w, https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2025\/02\/image-11-300x45.png 300w, https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2025\/02\/image-11-768x116.png 768w, https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2025\/02\/image-11.png 1163w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>So let&#8217;s do a quick digression to the <a href=\"https:\/\/developer.microsoft.com\/en-us\/graph\/graph-explorer\" target=\"_blank\" rel=\"noreferrer noopener\">Microsoft Graph Explorer<\/a> to see what data we can grab via the API. To run the query we need to have the following permissions: <code>DeviceManagementConfiguration.Read<\/code><\/p>\n\n\n\n<p>Now we can fire a request to the following URL (replace {ScriptID} with the ID you have copied in the step above). <\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">HTTP<\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>https:\/\/graph.microsoft.com\/beta\/deviceManagement\/deviceManagementScripts\/{ScriptID}\/deviceRunStates?`$expand=managedDevice<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D4D4D4\">https:\/\/graph.microsoft.com\/beta\/deviceManagement\/deviceManagementScripts\/{ScriptID}\/deviceRunStates?`$expand=managedDevice<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>As you can see, you get the number of results in the <code>@odata.count<\/code> node and all the results in the <code>value<\/code> -&gt; <code>resultMessage<\/code> nodes.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"582\" src=\"https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2025\/02\/image-5-1024x582.png\" alt=\"\" class=\"wp-image-531\" srcset=\"https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2025\/02\/image-5-1024x582.png 1024w, https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2025\/02\/image-5-300x170.png 300w, https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2025\/02\/image-5-768x436.png 768w, https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2025\/02\/image-5.png 1354w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>So, let&#8217;s put a small PowerShell script together, to fetch that data and consolidate it into one object.<\/p>\n\n\n\n<p>As with the request above, we need the Script-ID, then we connect to Graph and fire the same request.<\/p>\n\n\n\n<p>After that we just need to filter for successful runs of the script, parse the data and in this case, print it with <code>Out-GridView<\/code> to the screen.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">PowerShell<\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>$ScriptID = \"b0b6d415-2d29-4890-bc90-b0023dd6aa44\"\n\nConnect-MgGraph `\n    -Scopes \"DeviceManagementScripts.Read.All, DeviceManagementScripts.ReadWrite.All\"\n\n$result = Invoke-MgGraphRequest `\n    -Method GET `\n    -Uri \"beta\/deviceManagement\/deviceManagementScripts\/$($ScriptID)\/deviceRunStates?`$expand=managedDevice\"\n\n$success = $result.value | Where-Object -Property errorCode -EQ 0 \n$resultMessage = $success.resultMessage \n$objectResultMessage = $resultMessage | ConvertFrom-Json \n$objectResultMessage | Out-GridView<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #9CDCFE\">$ScriptID<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #CE9178\">&quot;b0b6d415-2d29-4890-bc90-b0023dd6aa44&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">Connect-MgGraph<\/span><span style=\"color: #D4D4D4\"> `<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    -Scopes <\/span><span style=\"color: #CE9178\">&quot;DeviceManagementScripts.Read.All, DeviceManagementScripts.ReadWrite.All&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">$result<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #DCDCAA\">Invoke-MgGraphRequest<\/span><span style=\"color: #D4D4D4\"> `<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    -Method GET `<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    -Uri <\/span><span style=\"color: #CE9178\">&quot;beta\/deviceManagement\/deviceManagementScripts\/<\/span><span style=\"color: #569CD6\">$(<\/span><span style=\"color: #9CDCFE\">$ScriptID<\/span><span style=\"color: #569CD6\">)<\/span><span style=\"color: #CE9178\">\/deviceRunStates?<\/span><span style=\"color: #D7BA7D\">`$<\/span><span style=\"color: #CE9178\">expand=managedDevice&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">$success<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #9CDCFE\">$result<\/span><span style=\"color: #DCDCAA\">.value<\/span><span style=\"color: #D4D4D4\"> | <\/span><span style=\"color: #DCDCAA\">Where-Object<\/span><span style=\"color: #D4D4D4\"> -Property errorCode -EQ <\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">$resultMessage<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #9CDCFE\">$success<\/span><span style=\"color: #DCDCAA\">.resultMessage<\/span><span style=\"color: #D4D4D4\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">$objectResultMessage<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #9CDCFE\">$resultMessage<\/span><span style=\"color: #D4D4D4\"> | <\/span><span style=\"color: #DCDCAA\">ConvertFrom-Json<\/span><span style=\"color: #D4D4D4\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">$objectResultMessage<\/span><span style=\"color: #D4D4D4\"> | <\/span><span style=\"color: #DCDCAA\">Out-GridView<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>And the results look as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"231\" src=\"https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2025\/02\/image-8-1024x231.png\" alt=\"\" class=\"wp-image-539\" srcset=\"https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2025\/02\/image-8-1024x231.png 1024w, https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2025\/02\/image-8-300x68.png 300w, https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2025\/02\/image-8-768x173.png 768w, https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2025\/02\/image-8.png 1426w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Of course, you can also create a CSV-File that use can use in other Applications like Excel for further editing:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">PowerShell<\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>$objectResultMessage | Export-Csv -Delimiter \",\" -Encoding UTF8 -Path \"Windows11Readiness.csv\"<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #9CDCFE\">$objectResultMessage<\/span><span style=\"color: #D4D4D4\"> | <\/span><span style=\"color: #DCDCAA\">Export-Csv<\/span><span style=\"color: #D4D4D4\"> -Delimiter <\/span><span style=\"color: #CE9178\">&quot;,&quot;<\/span><span style=\"color: #D4D4D4\"> -Encoding UTF8 -Path <\/span><span style=\"color: #CE9178\">&quot;Windows11Readiness.csv&quot;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>With the following result.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"193\" src=\"https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2025\/02\/image-9-1024x193.png\" alt=\"\" class=\"wp-image-540\" srcset=\"https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2025\/02\/image-9-1024x193.png 1024w, https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2025\/02\/image-9-300x57.png 300w, https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2025\/02\/image-9-768x145.png 768w, https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2025\/02\/image-9.png 1136w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>Even though this solution is not that native to Intune, it is still very easy to use, flexible and does not require any additional Service like a File-Share to store data, as it fetches the results from Intune itself. There are multiple use cases, like fetching Device-Hashes for Autopilot in case you need to enroll multiple devices in a new tenant.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>While Intune stores some information about the devices it manages, at some point you will need some additional data. And with some extra steps, it is possible to fetch a custom inventory from the devices. In this blog, we are going to fetch the Windows 11 readiness of all managed devices. This is done with [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":538,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[15,16,17,14,18,35],"class_list":["post-217","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-endpoint-management","tag-epm","tag-intune","tag-inventory","tag-powershell","tag-scripts","tag-windows-11"],"_links":{"self":[{"href":"https:\/\/digitalmaterial.ch\/blog\/wp-json\/wp\/v2\/posts\/217","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/digitalmaterial.ch\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/digitalmaterial.ch\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/digitalmaterial.ch\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/digitalmaterial.ch\/blog\/wp-json\/wp\/v2\/comments?post=217"}],"version-history":[{"count":30,"href":"https:\/\/digitalmaterial.ch\/blog\/wp-json\/wp\/v2\/posts\/217\/revisions"}],"predecessor-version":[{"id":843,"href":"https:\/\/digitalmaterial.ch\/blog\/wp-json\/wp\/v2\/posts\/217\/revisions\/843"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/digitalmaterial.ch\/blog\/wp-json\/wp\/v2\/media\/538"}],"wp:attachment":[{"href":"https:\/\/digitalmaterial.ch\/blog\/wp-json\/wp\/v2\/media?parent=217"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/digitalmaterial.ch\/blog\/wp-json\/wp\/v2\/categories?post=217"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/digitalmaterial.ch\/blog\/wp-json\/wp\/v2\/tags?post=217"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}