Blog Post

Device Management in Microsoft
2 MIN READ

How to collect custom inventory from Azure AD Joined devices

MikeGriz's avatar
MikeGriz
Icon for Microsoft rankMicrosoft
Apr 22, 2021

Kubilay Dagdelen on my team worked with several other folks to pull together a method for doing some custom inventory collection with Intune.  There are some performance delays that can be encountered if over-used, but it can be handy at times.

 

ConfigMgr admins love extending hardware inventory and collecting data from Windows devices.
Did you know Intune can do the same?!
The answer is Intune PowerShell scripts! Also known as SideCar… IME… Intune Management Extensions…

Well, IME is just another channel that runs parallel to MDM that sort of acts like the ConfigMgr client. We deliver different features over this channel: PowerShell scripts, Win32 apps, Proactive Remediation scripts, Win32 app log collection…


Can you give us an example?
Maybe you are interested to know more about Win32_BIOS.
Run the following PowerShell one-liner on a device

 

 

 

Get-WmiObject -Class Win32_BIOS |
select CurrentLanguage,
Description,
EmbeddedControllerMajorVersion,
EmbeddedControllerMinorVersion,
Manufacturer,
ReleaseDate,
SerialNumber | ConvertTo-Json -Compress

 

 


Script outputs the following:

 

Beautified:

 

 

{
"CurrentLanguage": "en-US",
"Description": "N2EET43W (1.25 )",
"EmbeddedControllerMajorVersion": 1,
"EmbeddedControllerMinorVersion": 13,
"Manufacturer": "LENOVO",
"ReleaseDate": "20191028000000.000000+000",
"SerialNumber": "12345678"
}

 

 


Let’s create an Intune PowerShell script and deploy it to some users/devices to demonstrate Win32_BIOS data as an example.


Tip: <scriptId> is stored in the URL


You can access the data via the following Graph endpoint in graph explorer
https://graph.microsoft.com/beta/deviceManagement/deviceManagementScripts/<scriptID>/deviceRunStates?$expand=managedDevice

 

It turns out that we store the above-mentioned script output in a property on the service side. If you are familiar with Graph Explorer, then you can take a look at the results


In the property “resultMessage”:


How do I see the data from all devices?
Prerequisites:
Install-Module -Name Microsoft.Graph.Intune


You need one more script to retrieve your results from Graph…

 

 

Update-MSGraphEnvironment -SchemaVersion 'beta'
Connect-MSGraph

$result = Invoke-MSGraphRequest -HttpMethod GET -Url 'deviceManagement/deviceManagementScripts/b113448a-528a-4beb-b7d5-381a117d5184/deviceRunStates?$expand=managedDevice' | Get-MSGraphAllPages
$success = $result| Where-Object -Property errorCode -EQ 0
$resultMessage = $success.resultMessage 
$objResultMessage = $resultMessage | ConvertFrom-Json
$objResultMessage | Out-GridView 

 

 

 


You can store the data in Log Analytics, SQL etc and visualize the way you want.
Enjoy!

Updated Jun 03, 2021
Version 2.0