Skip to content

Get-MgmtGraphTroubleshootingEvent

MgmtGraph: Audits Intune troubleshooting events

#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('DeviceManagementTroubleshootingEventId', $Identity)
        }
        else {
            $params.Add('All', $true)
        }

        $events = Get-MgDeviceManagementTroubleshootingEvent @params
        
        $results = foreach ($e in $events) {
            [PSCustomObject]@{
                EventDateTime = $e.EventDateTime
                CorrelationId = $e.CorrelationId
                TroubleshootingType = $e.OdataType
                Id            = $e.Id
                Timestamp     = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
            }
        }

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

Optional. Specifies the ID of the troubleshooting event to retrieve. If omitted, all events are listed.

An interactive directory of PowerShell scripts.