Skip to content

Get-MgmtGraphDeviceCategory

MgmtGraph: Audits Intune device categories

#Requires -Version 5.1
#Requires -Modules Microsoft.Graph.DeviceManagement

[CmdletBinding()]
Param (
    [Parameter(Position = 0)]
    [string]$Identity
)

Process {
    try {
        $params = @{
            'ErrorAction' = 'Stop'
        }

        if ($Identity) {
            $params.Add('DeviceCategoryId', $Identity)
        }
        else {
            $params.Add('All', $true)
        }

        $categories = Get-MgDeviceManagementDeviceCategory @params
        
        $results = foreach ($c in $categories) {
            [PSCustomObject]@{
                DisplayName = $c.DisplayName
                Description = $c.Description
                Id          = $c.Id
                Timestamp   = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
            }
        }

        Write-Output ($results | Sort-Object DisplayName)
    }
    catch {
        throw
    }
}

Optional. Specifies the ID of the device category to retrieve. If omitted, all categories are listed.

An interactive directory of PowerShell scripts.