fix: keep the installation when the first NetBox sync fails

The Intune installation state now only depends on the installed files and the
scheduled task; a temporary NetBox or network error during the first sync no
longer fails the installation.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
MrBlakeandClaude Opus 5.5 committed 2026-11-18 11:00:13 +01:00
1 parent 74183d4ef3
commit d632f0d383
1 file changed
+10 -2
+10 -2
View File
@@ -26,6 +26,14 @@ $principal = New-ScheduledTaskPrincipal -UserId 'S-1-5-18' -LogonType ServiceAcc
$settings = New-ScheduledTaskSettingsSet -StartWhenAvailable -ExecutionTimeLimit (New-TimeSpan -Minutes 15)
Register-ScheduledTask -TaskName 'NetBox Windows Agent' -Action $action -Trigger $trigger -Principal $principal -Settings $settings -Force | Out-Null
& $agentPath --config $configPath
if ($LASTEXITCODE -ne 0) { throw "Die erste NetBox-Synchronisation ist mit Exitcode $LASTEXITCODE fehlgeschlagen." }
Write-Host 'NetBox Windows Agent wurde erfolgreich installiert und synchronisiert.'
$syncExitCode = $LASTEXITCODE
if ($syncExitCode -ne 0) {
Write-Warning "Der Agent wurde installiert, aber die erste NetBox-Synchronisation ist mit Exitcode $syncExitCode fehlgeschlagen. Die geplante Aufgabe versucht es erneut."
} else {
Write-Host 'Die erste NetBox-Synchronisation war erfolgreich.'
}
if (-not (Test-Path -LiteralPath $agentPath)) { throw 'Installation fehlgeschlagen: agent.exe wurde nicht installiert.' }
if (-not (Test-Path -LiteralPath $configPath)) { throw 'Installation fehlgeschlagen: config.json wurde nicht installiert.' }
if (-not (Get-ScheduledTask -TaskName 'NetBox Windows Agent' -ErrorAction SilentlyContinue)) { throw 'Installation fehlgeschlagen: Die geplante Aufgabe fehlt.' }
Write-Host 'NetBox Windows Agent wurde erfolgreich installiert.'
exit 0