IntuneManagement icon indicating copy to clipboard operation
IntuneManagement copied to clipboard

Feature request: Device Inventory

Open royklo opened this issue 11 months ago • 4 comments

Device inventory is currently available. This one is of course still missing (yet).

URI: https://graph.microsoft.com/beta/deviceManagement/inventoryPolicies

royklo avatar Jan 08 '25 15:01 royklo

Hello,

I have added this locally. However. The API is still not working. Not the first time I see they release a new feature and the API is not working.

I'll see if I can dig into this a little bit more on the weekend

Cheers!

Micke-K avatar Jan 09 '25 11:01 Micke-K

Great! Hopefully they publish this soon!

royklo avatar Jan 16 '25 10:01 royklo

Im by all means no expert here.

https://graph.microsoft.com/beta/deviceManagement/inventoryPolicies you get the ID from here.

The script under, ofc with Copilot and my crazy back and forth testing

It seems to query https://graph.microsoft.com/beta/deviceManagement/inventoryCategories?&$filter=(platforms%20has%20%27windows10%27)%20and%20(technologies%20has%20%27extensibility%27)

# Read scopes are enough here; add ServiceConfig if needed in your tenant
Connect-MgGraph -Scopes `
  "DeviceManagementConfiguration.Read.All",
  "DeviceManagementServiceConfig.Read.All" `
  -UseDeviceCode

# -------------------------------
# 1) Build headers (include OData)
# -------------------------------
$token = "Your Token here"

$headers = @{
  Authorization = "Bearer $token"
  Accept        = "application/json;odata.metadata=full"     # include @odata.* metadata
  Prefer        = 'odata.include-annotations="*"'            # include all OData annotations
}

# ---------------------------------------------
# 2) Build the request URI with a clean $filter
#    (escape $ as `$ in PowerShell strings)
# ---------------------------------------------
$filter = "(platforms has 'windows10') and (technologies has 'extensibility')"

# If you want to control order/selection/count, you can add:
# $select = "id,description,categoryDescription"
# $orderby = "description"
# $uri = "https://graph.microsoft.com/beta/deviceManagement/inventoryCategories?`$filter=$([uri]::EscapeDataString($filter))&`$select=$select&`$orderby=$orderby&`$count=true"

$uri = "https://graph.microsoft.com/beta/deviceManagement/inventoryCategories?`$filter=$([uri]::EscapeDataString($filter))"

# ---------------------------------
# 3) Call Graph and parse JSON
# ---------------------------------
# Invoke-RestMethod parses JSON into a PSCustomObject automatically
$result = Invoke-RestMethod -Method GET -Uri $uri -Headers $headers

# ---------------------------------
# 4) Pretty JSON (preserves @odata)
# ---------------------------------
# This prints the full response including @odata.context, etc.
$result | ConvertTo-Json -Depth 25 | Out-Host

# ---------------------------------
# 5) Human-friendly table
# ---------------------------------
# Adjust columns as you like; use Format-List * to see all fields.
if ($null -ne $result.value) {
    $result.value |
      Select-Object id, description, categoryDescription |
      Sort-Object description |
      Format-Table -AutoSize
}
else {
    Write-Host "No rows returned." -ForegroundColor Yellow
}

# ---------------------------------
# 6) Access OData annotations directly
# ---------------------------------
# Properties starting with @ must be quoted
"`nOData Context: $($result.'@odata.context')"
if ($result.PSObject.Properties.Name -contains '@odata.count') {
    "Count       : $($result.'@odata.count')"
}

MikkelsenBrenno avatar Nov 06 '25 13:11 MikkelsenBrenno

Output, its prolly not formatted right, as i dont know how the tool works under the hood. But hopefully this helps :)

Image

MikkelsenBrenno avatar Nov 06 '25 13:11 MikkelsenBrenno