feat(export): use the Graph batch API by default for headless export

Headless export now fetches objects 20 per $batch call (was one call per
object because UseBatchAPI defaulted to off). -NoBatchApi on
Export-Policies.ps1 / Start-HeadlessIntune.ps1 falls back to single calls.

Adds per-run setting overrides ($global:SettingOverrides, consulted by
Get-SettingValue, set by Invoke-IntuneHeadlessBatch and never persisted).
Verify on a tenant by exporting with and without -NoBatchApi and comparing
the two folders with Compare-Tenants.py.
This commit is contained in:
2026-11-24 12:27:16 +01:00
parent b8e333f92d
commit 77440ffe36
4 changed files with 29 additions and 6 deletions
+16 -5
View File
@@ -134,7 +134,9 @@ function Invoke-IntuneHeadlessBatch
[string]$SettingsFile,
[string]$BatchFile
[string]$BatchFile,
[hashtable]$SettingOverrides
)
if(($AuthMode -eq "Browser" -or $AuthMode -eq "DeviceCode") -and -not $AppId)
@@ -226,11 +228,13 @@ function Invoke-IntuneHeadlessBatch
$invokeParams.Certificate = $Certificate
}
$global:SettingOverrides = $SettingOverrides
Import-Module $runtimeModule -Force
Initialize-IntuneManagementRuntime -View "IntuneGraphAPI" @invokeParams
}
finally
{
$global:SettingOverrides = $null
if($deleteBatchFile -and (Test-Path $BatchFile))
{
Remove-Item -LiteralPath $BatchFile -Force -ErrorAction SilentlyContinue
@@ -273,7 +277,10 @@ function Export-IntunePolicies
[switch]$IncludeAssignments,
[switch]$AddCompanyName
[switch]$AddCompanyName,
# Batch API (20 objects per call) is on for export; use this to fall back to one call per object
[switch]$NoBatchApi
)
$batchConfig = [PSCustomObject]@{
@@ -298,7 +305,8 @@ function Export-IntunePolicies
-RedirectUri $RedirectUri `
-BatchConfig $batchConfig `
-SettingsFile $SettingsFile `
-BatchFile $BatchFile
-BatchFile $BatchFile `
-SettingOverrides @{ UseBatchAPI = (-not $NoBatchApi) }
}
function Import-IntunePolicies
@@ -418,7 +426,9 @@ function Invoke-IntunePolicyAction
[switch]$IncludeScopeTags,
[switch]$ReplaceDependencyIds
[switch]$ReplaceDependencyIds,
[switch]$NoBatchApi
)
switch($Action)
@@ -441,7 +451,8 @@ function Invoke-IntunePolicyAction
-NameReplacePattern $NameReplacePattern `
-ObjectTypes $ObjectTypes `
-IncludeAssignments:$IncludeAssignments `
-AddCompanyName:$AddCompanyName
-AddCompanyName:$AddCompanyName `
-NoBatchApi:$NoBatchApi
}
"Import"
{