param( [Parameter(Mandatory)][string]$DbSliceExe, [string]$JobPath = (Join-Path $PSScriptRoot 'service-upsert.job.json'), [string]$LogDirectory = (Join-Path $PSScriptRoot 'logs') ) $ErrorActionPreference = 'Stop' try { $exePath = (Resolve-Path -LiteralPath $DbSliceExe).Path $jobFullPath = (Resolve-Path -LiteralPath $JobPath).Path if (-not (Test-Path -LiteralPath $exePath -PathType Leaf)) { throw 'Executable is not a file.' } if (-not (Test-Path -LiteralPath $jobFullPath -PathType Leaf)) { throw 'Job is not a file.' } $null = New-Item -ItemType Directory -Path $LogDirectory -Force $logFolder = (Resolve-Path -LiteralPath $LogDirectory).Path $runId = (Get-Date -Format 'yyyyMMdd-HHmmss-fff') + '-' + [guid]::NewGuid().ToString('N').Substring(0,8) $logPath = Join-Path $logFolder "service-upsert-$runId.log" # Start-Process waits for this Windows GUI-subsystem executable explicitly. $arguments = @(('"' + $jobFullPath + '"'), ('"' + $logPath + '"')) $process = Start-Process -FilePath $exePath -ArgumentList $arguments -Wait -PassThru -WindowStyle Hidden if (Test-Path -LiteralPath $logPath) { Get-Content -LiteralPath $logPath } Write-Output "CLI exit code: $($process.ExitCode)" Write-Output "Log file: $logPath" exit $process.ExitCode } catch { Write-Error 'Unable to launch the job. Check the executable, job path, and log directory permissions.' -ErrorAction Continue exit 2 }