[CmdletBinding()] param( [Parameter(Mandatory = $true)] [string]$ReleaseRoot, [Parameter(Mandatory = $true)] [ValidatePattern("^[A-Za-z0-9._-]{1,96}$")] [string]$RunId ) $ErrorActionPreference = "Stop" $taskName = "MissionCore-M49T1GSeg3D" $release = (Resolve-Path -LiteralPath $ReleaseRoot).Path $payload = Join-Path $release "payload" $runner = Join-Path $payload "Invoke-M49T1GSeg3DQualification.ps1" if (-not (Test-Path -LiteralPath $runner -PathType Leaf)) { throw "M49 T1 runner is missing" } $existing = Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue if ($existing -and $existing.State -eq "Running") { throw "$taskName is already running" } $powerShell = "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell.exe" $arguments = @( "-NoLogo", "-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-File", "`"$runner`"", "-BuildContext", "`"$payload`"", "-RunId", "`"$RunId`"" ) -join " " $userId = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name $action = New-ScheduledTaskAction ` -Execute $powerShell ` -Argument $arguments ` -WorkingDirectory $payload $principal = New-ScheduledTaskPrincipal ` -UserId $userId ` -LogonType Interactive ` -RunLevel Limited $trigger = New-ScheduledTaskTrigger -Once -At ((Get-Date).AddMinutes(30)) $settings = New-ScheduledTaskSettingsSet ` -AllowStartIfOnBatteries ` -DontStopIfGoingOnBatteries ` -StartWhenAvailable ` -ExecutionTimeLimit ([TimeSpan]::FromHours(3)) Register-ScheduledTask ` -TaskName $taskName ` -Action $action ` -Principal $principal ` -Trigger $trigger ` -Settings $settings ` -Description "One-shot M49 T1 pinned GSeg3D upstream qualification." ` -Force | Out-Null Start-ScheduledTask -TaskName $taskName [pscustomobject]@{ task_name = $taskName run_id = $RunId release_root = $release state = (Get-ScheduledTask -TaskName $taskName).State.ToString() } | ConvertTo-Json -Compress