[CmdletBinding()] param( [ValidateSet("Export","Import")] [string]$Action, [Parameter(Mandatory = $true)] [string]$TenantId, [string]$AppId, [string]$Secret, [string]$Certificate, [ValidateSet("AppOnly","Browser","DeviceCode")] [string]$AuthMode = "AppOnly", [string]$RedirectUri, [string]$SettingsFile, [string]$BatchFile, [string]$NameFilter = "", [string]$NameSearchPattern = "", [string]$NameReplacePattern = "", [string[]]$ObjectTypes, [string]$ExportPath, [string]$ImportPath, [ValidateSet("alwaysImport","skipIfExist","replace","replace_with_assignments","update")] [string]$ImportType = "alwaysImport", [switch]$IncludeAssignments, [switch]$AddCompanyName, [switch]$IncludeScopeTags, [switch]$ReplaceDependencyIds, [switch]$Interactive ) $modulePath = Join-Path $PSScriptRoot "Headless/IntuneManagement.Headless.psd1" Import-Module $modulePath -Force if($Interactive -and -not $Action) { Write-Host "Interactive mode will prompt for the action and other settings." -ForegroundColor Cyan } elseif(-not $Action) { throw "Action is required. Use -Interactive to select it in a terminal UI." } if($Interactive) { $tuiScript = Join-Path $PSScriptRoot "Scripts/Start-IntuneManagementTui.ps1" if(Test-Path $tuiScript) { $tuiResult = & $tuiScript if(-not $tuiResult) { Write-Host "No selection made. Exiting." -ForegroundColor Yellow; exit 0 } foreach($prop in $tuiResult.PSObject.Properties) { if($prop.Value -ne $null -and $prop.Name -ne "Action") { Set-Variable -Name $prop.Name -Value $prop.Value } elseif($prop.Name -eq "Action") { $Action = $prop.Value } } } else { throw "TUI script not found: $tuiScript" } } $invokeParams = @{ Action = $Action TenantId = $TenantId AppId = $AppId AuthMode = $AuthMode SettingsFile = $SettingsFile BatchFile = $BatchFile NameFilter = $NameFilter NameSearchPattern = $NameSearchPattern NameReplacePattern = $NameReplacePattern ExportPath = $ExportPath ImportPath = $ImportPath ImportType = $ImportType IncludeAssignments = $IncludeAssignments AddCompanyName = $AddCompanyName IncludeScopeTags = $IncludeScopeTags ReplaceDependencyIds = $ReplaceDependencyIds } if($Interactive -and $Action) { $invokeParams.Action = $Action } if($PSBoundParameters.ContainsKey("ObjectTypes") -or $ObjectTypes) { $invokeParams.ObjectTypes = $ObjectTypes } if($Secret) { $invokeParams.Secret = $Secret } elseif($Certificate) { $invokeParams.Certificate = $Certificate } if($RedirectUri) { $invokeParams.RedirectUri = $RedirectUri } Invoke-IntunePolicyAction @invokeParams