### FILE: README.md # Intune Faster Device Management Validator This repository provides a small production-ready tool to validate (with evidence) whether Intune-managed device reporting is updating sooner by querying Microsoft Graph managed device fields such as **lastSyncDateTime** and **managementState**. It is intentionally scoped to a single device (or multiple runs) to support fast operational checks without “guesswork, vibes, or repeated Sync”. ## What it does - Connects to Microsoft Graph with least-privilege delegated scopes. - Fetches managed device records for a target device name. - Reports: - `deviceName` - `lastSyncDateTime` - `managementState` - `operatingSystem` - `ownerType` - `azureADDeviceId` - Includes retry logic for transient 429/503 responses. ## Usage See `scripts/Check-IntuneManagedDevice.ps1`. ### FILE: scripts/Check-IntuneManagedDevice.ps1 <# .SYNOPSIS Queries Microsoft Graph for an Intune managed device and prints key sync/completion fields. .DESCRIPTION This script connects to Microsoft Graph using delegated permissions and retrieves a managed device record for a target device name as shown in the Intune admin center. It focuses on operational validation of the "faster device management visibility" reporting loop by comparing timestamps/state values visible in Intune with values returned by Graph. The script includes retry-safe handling for transient HTTP 429/503 responses. .NOTES Author: Souhaiel Morhag Company: MSEndpoint.com Blog: https://msendpoint.com Academy: https://app.msendpoint.com/academy LinkedIn: https://linkedin.com/in/souhaiel-morhag GitHub: https://github.com/Msendpoint License: MIT .EXAMPLE . \Check-IntuneManagedDevice.ps1 -DeviceName "CONTOSO-LT-042" .EXAMPLE . \Check-IntuneManagedDevice.ps1 -DeviceName "CONTOSO-LT-042" -MaxAttempts 6 -InitialRetrySeconds 2 #> [CmdletBinding()] param( [Parameter(Mandatory = $true, Position = 0)] [ValidateNotNullOrEmpty()] [string]$DeviceName, [Parameter(Mandatory = $false)] [ValidateRange(1, 20)] [int]$MaxAttempts = 4, [Parameter(Mandatory = $false)] [ValidateRange(1, 60)] [int]$InitialRetrySeconds = 5 ) Set-StrictMode -Version Latest $ErrorActionPreference = 'Stop' function Get-DeviceManagedRecordUri { param( [Parameter(Mandatory = $true)] [string]$Name ) # NOTE: Use beta to match the article's direction. # If your org requires v1.0, adjust endpoint accordingly. $encodedName = $Name.Replace("'", "''") return "https://graph.microsoft.com/beta/deviceManagement/managedDevices?$filter=deviceName eq '$encodedName'&$select=id,deviceName,lastSyncDateTime,managementState,ownerType,operatingSystem,azureADDeviceId" } function Invoke-GraphGetWithRetry { param( [Parameter(Mandatory = $true)] [string]$Uri, [Parameter(Mandatory = $false)] [int]$Attempts = 4, [Parameter(Mandatory = $false)] [int]$InitialDelaySeconds = 5 ) for ($i = 1; $i -le $Attempts; $i++) { try { # Use Invoke-MgGraphRequest to allow direct REST with the constructed URI. $resp = Invoke-MgGraphRequest -Method GET -Uri $Uri -OutputType PSObject return $resp } catch { $msg = $_.Exception.Message $isTransient = ($msg -match '429|503') if (-not $isTransient -or $i -ge $Attempts) { throw } # Backoff: 5s, 10s, 15s... (simple linear backoff as in the article example, but configurable) $sleepSeconds = ($InitialDelaySeconds * $i) Write-Warning ("Transient Graph error detected (attempt {0}/{1}). Sleeping {2}s then retrying. Error: {3}" -f $i, $Attempts, $sleepSeconds, $msg) Start-Sleep -Seconds $sleepSeconds } } throw "Graph request failed after $Attempts attempts." } try { # Connect with least-privilege delegated scopes. # Scopes from the article: # - DeviceManagementManagedDevices.Read.All # - DeviceManagementConfiguration.Read.All Write-Verbose 'Connecting to Microsoft Graph with delegated read scopes...' $scopes = @( 'DeviceManagementManagedDevices.Read.All', 'DeviceManagementConfiguration.Read.All' ) # Avoid re-prompting if already connected $graphContext = Get-MgContext -ErrorAction SilentlyContinue if (-not $graphContext -or -not $graphContext.Account) { Connect-MgGraph -Scopes $scopes | Out-Null } else { # If context exists, still ensure required scopes were granted. # We won't strictly validate scopes here (Graph SDK does not expose granted scopes reliably). } $uri = Get-DeviceManagedRecordUri -Name $DeviceName Write-Verbose ("Querying managed device record for DeviceName='{0}'" -f $DeviceName) $result = Invoke-GraphGetWithRetry -Uri $uri -Attempts $MaxAttempts -InitialDelaySeconds $InitialRetrySeconds if (-not $result -or -not $result.value) { Write-Output ("No managed device record found for DeviceName: {0}" -f $DeviceName) exit 0 } $result.value | Select-Object deviceName, lastSyncDateTime, managementState, ownerType, operatingSystem, azureADDeviceId | Format-Table -AutoSize } catch { Write-Error ("Failed to check Intune managed device state. {0}" -f $_.Exception.Message) throw } ### FILE: src/index.php graphCall($endpoint, $accessToken, 'GET'); $items = $resp['value'] ?? []; if (!is_array($items) || count($items) === 0) { render_premium_card('No managed device found', "DeviceName: {$deviceName}", null, 'down', '🧭'); return; } // If multiple devices share the same name, show top results. $first = $items[0]; $lastSync = $first['lastSyncDateTime'] ?? ''; $managementState = $first['managementState'] ?? ''; // Simple trend heuristics (not authoritative): earlier/later depends on your rollout. // Here we just display values; the UI trends can be enhanced if you wire in comparisons. render_premium_card( 'Device', $first['deviceName'] ?? '-', null, 'up', '💻' ); render_premium_card( 'Last Sync (Graph)', $lastSync !== '' ? $lastSync : '-', null, 'up', '⏱️' ); render_premium_card( 'Management State (Graph)', $managementState !== '' ? $managementState : '-', null, 'up', '✅' ); render_premium_card( 'Operating System', $first['operatingSystem'] ?? '-', null, 'up', '🪟' ); render_premium_card( 'Owner Type', $first['ownerType'] ?? '-', null, 'up', '👤' ); $count = count($items); render_premium_card( 'Matches', (string)$count, null, $count > 1 ? 'down' : 'up', '🔎' ); } catch (Throwable $e) { render_premium_card('Graph call failed', $e->getMessage(), null, 'down', '⚠️'); } ?> ### FILE: src/assets/placeholder.txt This repo focuses on production-ready script generation. UI styling is handled by the M365 SaaS Engine platform defaults.