Friday 4:47 PM. Security wants faster drift detection for a custom compliance check because a few Windows laptops were happily marked compliant long after a local control drifted. Meanwhile, the Mac team quite reasonably asks, “Are we really going to rerun this thing every 15 minutes on 8,000 endpoints?” That’s the actual problem here. Faster isn’t automatically better when the script itself is expensive, flaky, or tied to Conditional Access decisions that can bounce a user in and out of access like a dodgy VPN tunnel.
Microsoft Intune now supports configurable evaluation intervals for custom compliance scripts on Windows and macOS. The practical choices in the admin experience are the short cycles people usually want during an incident review: 15 minutes, 30 minutes, and then longer intervals up to 8 hours. The trick is setting the interval deliberately, verifying that Graph actually reflects the change in your tenant, and not publishing automation that guesses at a schema property name and then falls over the next time Microsoft moves a field. Portal labels change. Graph shapes drift. Friday evenings remain undefeated.
Reality check: this article sticks to automation patterns that verify schema first instead of pretending a friendly cmdlet already exists for every Intune setting. If your tenant doesn’t expose the interval property in Graph yet, use the portal, then use the read-only verification section below to confirm what the service returns.
When “check faster” turns into “why are all my laptops hot?”
This setting matters because custom compliance is one of the few places where admins routinely bolt business-specific logic onto compliance decisions. That logic can be elegant. It can also be a 400-line PowerShell or shell script held together by hope, regex, and one old comment saying “don’t touch this, it breaks finance.” Running that every 15 minutes across a large estate needs thought.
Short intervals improve drift detection. If your script checks for a disabled security control, missing agent, local config tampering, or an out-of-band requirement that built-in compliance can’t see, getting from “drift happened” to “device marked noncompliant” faster can be worth it. But more frequent evaluations also mean more endpoint work, more log churn, and a greater chance of temporary failures causing compliance noise.
| Interval | Best fit | Risk trade-off | My field take |
|---|---|---|---|
| 15 minutes | High-risk drift detection tied to access | Higher agent activity, more noise if script is fragile | Use only if the script is fast, deterministic, and you’ve tested failure behavior |
| 30 minutes | Balanced faster enforcement | Moderate extra activity | Usually the safest “faster than default” target for production pilots |
| 1–2 hours | Most enterprise custom checks | Slower drift detection | Good default when the script does heavier inspection |
| 4–8 hours | Low-risk or expensive evaluation | Longer noncompliant exposure window | Fine for informational controls that don’t need quick CA reaction |
Where the setting shows up, and what to validate before you touch it
As of late 2026, the feature is in Intune for Windows and macOS custom compliance policies. The service release note confirms the capability, but release notes rarely give you the full object model. So before automating anything, verify two things in your own tenant:
- Open the target custom compliance policy in Intune admin center > Devices > Compliance policies and confirm the interval selector is present for the platform.
- Read the current policy via Graph at /v1.0/deviceManagement/deviceCompliancePolicies and inspect the returned payload for the platform-specific custom compliance data and interval-related property.
- Only after you’ve captured the live schema should you attempt automation against it.
Don’t guess the property name. Intune policy payloads have a long history of being slightly different from what people expect from the UI label. If you hardcode a made-up property and publish it, the best case is a 400 Bad Request. The worse case is a silent no-op and a very confident CAB note that accomplished nothing.
Production script: discover, verify, and optionally patch custom compliance intervals
The script below does three jobs:
- Authenticates with Microsoft Graph PowerShell v2 using least-privilege practical scopes for Intune compliance policy administration.
- Enumerates Windows and macOS compliance policies and inspects the raw JSON for custom compliance and likely interval-related fields.
- If you provide a property path that you already validated in your tenant, it can patch that value safely with
-WhatIfsupport, retry handling for 429/5xx, and export of pre/post payloads for evidence.
| Requirement | Value | Notes |
|---|---|---|
| PowerShell | 7.x recommended | Works better for modern JSON handling and consistent Graph module behavior |
| Module | Microsoft.Graph.Authentication | Direct REST via Invoke-MgGraphRequest; no invented Intune cmdlets |
| Graph scopes | DeviceManagementConfiguration.Read.All / DeviceManagementConfiguration.ReadWrite.All | Use read-only for discovery; read-write only when patching |
| Target resources | Windows and macOS device compliance policies | Script filters returned policies to the relevant platforms |
| Supported mode | Discovery + controlled patch | Patch only after confirming the live property path in your tenant |
Connect-MgGraph -UseDeviceAuthentication for reliable MFA prompt support across Cloud Shell and headless administration servers.# Author: Souhaiel MORHAG | msendpoint.com
# License: MIT
# Required Scopes (Read Only): DeviceManagementConfiguration.Read.All
# Required Scopes (Patch): DeviceManagementConfiguration.ReadWrite.All
[CmdletBinding(SupportsShouldProcess=$true)]
Param (
[Parameter(Mandatory = $false,
[string]$Message,
[ValidateSet("INFO", "WARN", "ERROR", "OK",
[string[]]$Scopes,
[Parameter(Mandatory = $true,
[Parameter(Mandatory = $true,
[Parameter(Mandatory = $true
)]
[ValidateSet("Discover", "Patch")]
[string]$Mode = "Discover",
[Parameter(Mandatory = $false)]
[ValidateSet("windows10CompliancePolicy", "macOSCompliancePolicy", "All")]
[string]$Platform = "All",
[Parameter(Mandatory = $false)]
[string]$PolicyName,
[Parameter(Mandatory = $false)]
[ValidateSet("15m", "30m", "1h", "2h", "4h", "8h")]
[string]$Interval,
[Parameter(Mandatory = $false)]
[string]$IntervalPropertyPath,
[Parameter(Mandatory = $false)]
[string]$ExportPath = ".\Intune-CustomComplianceInterval-Audit",
[Parameter(Mandatory = $false)]
[int]$MaxRetryCount = 6
)
$ErrorActionPreference = "Stop"
function Write-Log {
]
[string]$Level = "INFO"
)
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
switch ($Level) {
"INFO" { Write-Host "[$timestamp] [INFO ] $Message" -ForegroundColor Cyan }
"WARN" { Write-Host "[$timestamp] [WARN ] $Message" -ForegroundColor Yellow }
"ERROR" { Write-Host "[$timestamp] [ERROR] $Message" -ForegroundColor Red }
"OK" { Write-Host "[$timestamp] [ OK ] $Message" -ForegroundColor Green }
}
}
function Ensure-GraphConnection {
try {
$ctx = Get-MgContext -ErrorAction SilentlyContinue
if (-not $ctx) {
Write-Log -Message "Connecting to Microsoft Graph..."
Connect-MgGraph -Scopes $Scopes -NoWelcome | Out-Null
} else {
Write-Log -Message "Using existing Microsoft Graph context for tenant $($ctx.TenantId)."
}
}
catch {
Write-Log -Level ERROR -Message "Failed to connect to Microsoft Graph. $($_.Exception.Message)"
exit 1
}
}
function Invoke-GraphRequestWithRetry {
]
[ValidateSet("GET", "PATCH")]
[string]$Method,
[Parameter(Mandatory = $true)]
[string]$Uri,
[Parameter(Mandatory = $false)]
[object]$Body
)
$attempt = 0
do {
try {
$attempt++
if ($PSBoundParameters.ContainsKey("Body")) {
return Invoke-MgGraphRequest -Method $Method -Uri $Uri -Body ($Body | ConvertTo-Json -Depth 20)
}
else {
return Invoke-MgGraphRequest -Method $Method -Uri $Uri
}
}
catch {
$statusCode = $null
$retryAfter = 0
if ($_.Exception.Response) {
try {
$statusCode = [int]$_.Exception.Response.StatusCode
if ($_.Exception.Response.Headers -and $_.Exception.Response.Headers.RetryAfter) {
$retryAfter = [int]$_.Exception.Response.Headers.RetryAfter.Delta.TotalSeconds
}
}
catch {
# header parsing can vary by module/runtime
}
}
if (($statusCode -eq 429) -or ($statusCode -ge 500 -and $statusCode -lt 600)) {
if ($attempt -ge $MaxRetryCount) {
throw
}
if ($retryAfter -le 0) {
$retryAfter = [math]::Min((2 * $attempt), 30)
}
Write-Log -Level WARN -Message "Graph returned HTTP $statusCode for $Method $Uri. Retrying in $retryAfter second(s). Attempt $attempt of $MaxRetryCount."
Start-Sleep -Seconds $retryAfter
}
else {
throw
}
}
} while ($attempt -lt $MaxRetryCount)
}
function Set-NestedValue {
]
[hashtable]$Target,
[Parameter(Mandatory = $true)]
[string]$Path,
[Parameter(Mandatory = $true)]
[object]$Value
)
$parts = $Path -split "\."
$current = $Target
for ($i = 0; $i -lt ($parts.Count - 1); $i++) {
$part = $parts[$i]
if (-not $current.ContainsKey($part) -or $null -eq $current[$part]) {
$current[$part] = @{}
}
$current = $current[$part]
}
$current[$parts[-1]] = $Value
return $Target
}
function Convert-IntervalToPayloadValue {
]
[string]$Interval
)
switch ($Interval) {
"15m" { return "15Minutes" }
"30m" { return "30Minutes" }
"1h" { return "1Hour" }
"2h" { return "2Hours" }
"4h" { return "4Hours" }
"8h" { return "8Hours" }
default { throw "Unsupported interval value: $Interval" }
}
}
try {
if (-not (Test-Path -Path $ExportPath)) {
New-Item -Path $ExportPath -ItemType Directory -Force | Out-Null
}
$requiredScopes = if ($Mode -eq "Patch") {
@("DeviceManagementConfiguration.ReadWrite.All")
}
else {
@("DeviceManagementConfiguration.Read.All")
}
Ensure-GraphConnection -Scopes $requiredScopes
$uri = "https://graph.microsoft.com/v1.0/deviceManagement/deviceCompliancePolicies"
Write-Log -Message "Retrieving compliance policies from Graph..."
$response = Invoke-GraphRequestWithRetry -Method "GET" -Uri $uri
$policies = @($response.value)
if (-not $policies -or $policies.Count -eq 0) {
Write-Log -Level WARN -Message "No compliance policies returned from Graph."
exit 0
}
$targetPolicies = foreach ($policy in $policies) {
$odataType = $policy.'@odata.type'
$isWindows = $odataType -match "windows"
$isMac = $odataType -match "macOS|mac"
if ($Platform -eq "All" -and ($isWindows -or $isMac)) {
$policy
}
elseif ($Platform -eq "windows10CompliancePolicy" -and $isWindows) {
$policy
}
elseif ($Platform -eq "macOSCompliancePolicy" -and $isMac) {
$policy
}
}
if ($PolicyName) {
$targetPolicies = $targetPolicies | Where-Object { $_.displayName -eq $PolicyName }
}
if (-not $targetPolicies) {
Write-Log -Level WARN -Message "No matching Windows/macOS compliance policies found."
exit 0
}
foreach ($policy in $targetPolicies) {
$policyId = $policy.id
$detailUri = "https://graph.microsoft.com/v1.0/deviceManagement/deviceCompliancePolicies/$policyId"
$detail = Invoke-GraphRequestWithRetry -Method "GET" -Uri $detailUri
$jsonPath = Join-Path -Path $ExportPath -ChildPath ("{0}-{1}-before.json" -f $detail.displayName.Replace(" ","_"), $detail.id)
$detail | ConvertTo-Json -Depth 20 | Out-File -FilePath $jsonPath -Encoding utf8
$detailJson = $detail | ConvertTo-Json -Depth 20
$hasCustomComplianceHints = ($detailJson -match "custom") -or ($detailJson -match "script") -or ($detailJson -match "complianceScript") -or ($detailJson -match "scheduledActionsForRule")
Write-Log -Message "Policy: $($detail.displayName)"
Write-Log -Message " Id: $($detail.id)"
Write-Log -Message " Type: $($detail.'@odata.type')"
Write-Log -Message " Exported raw payload to: $jsonPath"
if ($hasCustomComplianceHints) {
Write-Log -Level OK -Message " Payload contains custom compliance-related markers. Review exported JSON for the interval property."
}
else {
Write-Log -Level WARN -Message " No obvious custom compliance markers found in raw payload. Verify the policy really uses custom compliance in the portal."
}
if ($Mode -eq "Patch") {
if ([string]::IsNullOrWhiteSpace($IntervalPropertyPath)) {
throw "Patch mode requires -IntervalPropertyPath."
}
if ([string]::IsNullOrWhiteSpace($Interval)) {
throw "Patch mode requires -Interval."
}
$payloadValue = Convert-IntervalToPayloadValue -Interval $Interval
$patchBody = @{}
$patchBody = Set-NestedValue -Target $patchBody -Path $IntervalPropertyPath -Value $payloadValue
$patchPreviewPath = Join-Path -Path $ExportPath -ChildPath ("{0}-{1}-patch.json" -f $detail.displayName.Replace(" ","_"), $detail.id)
$patchBody | ConvertTo-Json -Depth 20 | Out-File -FilePath $patchPreviewPath -Encoding utf8
if ($PSCmdlet.ShouldProcess($detail.displayName, "Update custom compliance interval to $Interval via Graph")) {
Write-Log -Message "Patching policy using property path '$IntervalPropertyPath'..."
Invoke-GraphRequestWithRetry -Method "PATCH" -Uri $detailUri -Body $patchBody | Out-Null
Write-Log -Level OK -Message "Patch request submitted successfully for $($detail.displayName)."
$verify = Invoke-GraphRequestWithRetry -Method "GET" -Uri $detailUri
$afterPath = Join-Path -Path $ExportPath -ChildPath ("{0}-{1}-after.json" -f $verify.displayName.Replace(" ","_"), $verify.id)
$verify | ConvertTo-Json -Depth 20 | Out-File -FilePath $afterPath -Encoding utf8
Write-Log -Level OK -Message "Post-change payload exported to: $afterPath"
}
}
}
Write-Log -Level OK -Message "Completed successfully."
exit 0
}
catch {
Write-Log -Level ERROR -Message "Unhandled failure: $($_.Exception.Message)"
exit 1
}
How to use it without lying to yourself about supportability
The important part isn’t the PATCH. It’s the discovery workflow before the patch. If you already know the exact interval property exposed in your tenant’s policy payload, great. If not, the script’s discovery mode exports the full JSON for the policy so you can inspect it safely first.
-WhatIf where applicable.# Read-only discovery of all Windows and macOS compliance policies
pwsh .\Set-IntuneCustomComplianceInterval.ps1 -Mode Discover -Verbose
# Narrow to one policy by display name
pwsh .\Set-IntuneCustomComplianceInterval.ps1 -Mode Discover -PolicyName "Contoso - Windows Custom Compliance"
# Dry run a patch once you have the validated property path from your tenant
pwsh .\Set-IntuneCustomComplianceInterval.ps1 -Mode Patch -PolicyName "Contoso - macOS Custom Compliance" -Interval 30m -IntervalPropertyPath "customComplianceSettings.evaluationInterval" -WhatIf
# Execute the patch for real
pwsh .\Set-IntuneCustomComplianceInterval.ps1 -Mode Patch -PolicyName "Contoso - macOS Custom Compliance" -Interval 30m -IntervalPropertyPath "customComplianceSettings.evaluationInterval"
Critical: customComplianceSettings.evaluationInterval above is an example path only. Use discovery mode and inspect your exported JSON first. If your tenant exposes the setting differently, patch the real property. If it doesn’t expose it yet in Graph, stop there and use the admin center instead.
Graph verification: the boring part that saves your change record
After updating the interval, verify in three places.
- Portal: reopen the policy in Intune and confirm the selected interval displays as expected.
- Graph: rerun a
GETagainsthttps://graph.microsoft.com/v1.0/deviceManagement/deviceCompliancePoliciesor the specific policy ID and compare the exported payload before and after. - Device behavior: force a device sync, then check device compliance reporting timing in Intune device status.
GET https://graph.microsoft.com/v1.0/deviceManagement/deviceCompliancePolicies
/* Inspect the policy payload for the custom compliance interval field returned by your tenant */
On the service side, you’re mainly proving that the policy object holds the intended value. On the endpoint side, you’re proving that the new schedule actually changes how quickly compliance drift is picked up. Those are not always the same thing on the first sync, especially when devices are asleep, off-network, or just being themselves.
What to check on the endpoint when the compliance state lags behind
If you set a shorter interval and the device still seems stale, don’t immediately blame Graph. Check the local signals.
| Platform | What to inspect | Where | Why it matters |
|---|---|---|---|
| Windows | MDM event processing | Event Viewer > Applications and Services Logs > Microsoft > Windows > DeviceManagement-Enterprise-Diagnostics-Provider > Admin | Shows policy processing and MDM-side issues |
| Windows | Intune agent activity | %ProgramData%\Microsoft\IntuneManagementExtension\Logs\ |
Useful when people confuse custom compliance with script delivery behavior from IME |
| macOS | Intune management agent cadence | Agent logs on the device plus Intune device status timestamps | Confirms the device is actually checking in often enough |
| Both | Policy assignment and target scope | Intune admin center | The interval can be perfect and still do nothing if the wrong group got the policy |
Worth remembering: a shorter custom compliance evaluation interval doesn’t magically override every other timing factor. Device reachability, sync timing, user sign-in state, and service reporting latency still exist. Intune remains Intune. Sometimes it’s quick. Sometimes you get time to make coffee.
Choosing sane intervals for production
If the script is tiny, deterministic, and checks something security-sensitive, pilot 30 minutes first. If you’ve got a heavy script touching the file system, parsing logs, or querying multiple local subsystems, start at 1 hour or 2 hours. Reserve 15 minutes for cases where the business impact of delayed detection is genuinely higher than the device and support overhead.
Also test failure semantics. A script that occasionally times out, depends on a transient local service, or emits inconsistent JSON is exactly how you create noisy compliance flips and angry access tickets Monday morning. If the custom check gates Conditional Access, treat the script like code that can lock people out. Because it can.
Recommended rollout pattern: validate the policy payload in Graph, change the interval on a pilot policy first, sync a small Windows and macOS cohort, watch compliance transition timing for 24–48 hours, then expand. That beats discovering at scale that your “fast” interval mostly just made laptops busier and your helpdesk queue longer.