diff --git a/Core.psm1 b/Core.psm1 index 2a3c2dc..30a424a 100644 --- a/Core.psm1 +++ b/Core.psm1 @@ -792,6 +792,12 @@ function Get-SettingValue { param($Key, $DefaultValue, [switch]$GlobalOnly, [switch]$TenantOnly, $TenantID) + # Per-run overrides (e.g. set by the headless layer); never persisted to Settings.json + if($global:SettingOverrides -is [hashtable] -and $global:SettingOverrides.ContainsKey($Key)) + { + return $global:SettingOverrides[$Key] + } + $settingObj = $null foreach($section in $global:appSettingSections) { diff --git a/Headless/IntuneManagement.Headless.psm1 b/Headless/IntuneManagement.Headless.psm1 index ff9f846..b2a82c1 100644 --- a/Headless/IntuneManagement.Headless.psm1 +++ b/Headless/IntuneManagement.Headless.psm1 @@ -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" { diff --git a/Scripts/Export-Policies.ps1 b/Scripts/Export-Policies.ps1 index e7d4dc3..4140bcb 100644 --- a/Scripts/Export-Policies.ps1 +++ b/Scripts/Export-Policies.ps1 @@ -35,7 +35,10 @@ param( [switch]$IncludeAssignments, - [switch]$AddCompanyName + [switch]$AddCompanyName, + + # Batch API is on by default; this falls back to one Graph call per object + [switch]$NoBatchApi ) $modulePath = Join-Path (Split-Path -Parent $PSScriptRoot) "Headless/IntuneManagement.Headless.psd1" diff --git a/Scripts/Start-HeadlessIntune.ps1 b/Scripts/Start-HeadlessIntune.ps1 index 98e6533..8acc48d 100644 --- a/Scripts/Start-HeadlessIntune.ps1 +++ b/Scripts/Start-HeadlessIntune.ps1 @@ -52,6 +52,8 @@ param( [switch]$ReplaceDependencyIds, + [switch]$NoBatchApi, + [switch]$Interactive, # GenerateReports params @@ -237,6 +239,7 @@ $invokeParams = @{ AddCompanyName = $AddCompanyName IncludeScopeTags = $IncludeScopeTags ReplaceDependencyIds = $ReplaceDependencyIds + NoBatchApi = $NoBatchApi } if($Interactive -and $Action) { $invokeParams.Action = $Action }