imaging: idx=8 completion + Send-PxeStatus success+failure logging
Two related changes so the /imaging dashboard reaches 100% and so the
operator can see why POSTs are not arriving when a session stalls.
Monitor-IntuneProgress.ps1:
* After sync-complete.txt is written (DSC + lockdown done) fire a
final Send-PxeStatus -StageIndex 8 -StageTotal 8 -Status 'succeeded'
+ IntuneDeviceId. Previously the script exited without any final
status push, so even a perfect run capped at idx=7 / 87.5%. The
session now reaches 8/8 / 100% green when imaging actually finishes.
Send-PxeStatus.ps1:
* Log EVERY POST attempt (both success and failure) to C:\Logs\
send-pxe-status.log with idx, status, stage name, and either the
HTTP code on success or the exception message on failure. Was
previously silent-on-success, log-on-failure. Operator can now
correlate dashboard state to actual outbound activity:
OK idx=2/8 status=in_progress http=200 stage='Run-ShopfloorSetup: starting'
ERR idx=2/8 status=in_progress uri=http://10.9.100.1:9009/... err=Unable to connect
* Errors still swallowed - imaging never blocks on a failed status push.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -15,6 +15,10 @@ function Send-PxeStatus {
|
||||
[string]$Status = 'in_progress',
|
||||
[string]$Error_ = '',
|
||||
[string[]]$LogLines = @(),
|
||||
# Intune device ID (AAD/Entra device GUID from `dsregcmd /status`).
|
||||
# Only available post-AAD-join; pass it from Monitor-IntuneProgress
|
||||
# once captured. The dashboard renders a QR of this value.
|
||||
[string]$IntuneDeviceId = '',
|
||||
[string]$PxeServer = '10.9.100.1',
|
||||
[int]$Port = 9009,
|
||||
[int]$TimeoutSec = 5
|
||||
@@ -54,24 +58,35 @@ function Send-PxeStatus {
|
||||
stage_total = $StageTotal
|
||||
status = $Status
|
||||
}
|
||||
if ($Error_) { $payload.error = $Error_ }
|
||||
if ($LogLines) { $payload.log_lines = $LogLines }
|
||||
if ($Error_) { $payload.error = $Error_ }
|
||||
if ($LogLines) { $payload.log_lines = $LogLines }
|
||||
if ($IntuneDeviceId) { $payload.intune_device_id = $IntuneDeviceId }
|
||||
|
||||
$body = $payload | ConvertTo-Json -Compress
|
||||
$uri = "http://${PxeServer}:${Port}/imaging/status"
|
||||
|
||||
# Always log the attempt to C:\Logs\send-pxe-status.log so the operator
|
||||
# can correlate dashboard state against actual outbound POSTs. Logs both
|
||||
# success (one line per fired stage) and failure (with exception).
|
||||
$logFile = 'C:\Logs\send-pxe-status.log'
|
||||
try {
|
||||
Invoke-WebRequest -Uri $uri -Method POST `
|
||||
if (-not (Test-Path 'C:\Logs')) { New-Item -ItemType Directory -Path 'C:\Logs' -Force | Out-Null }
|
||||
} catch { }
|
||||
|
||||
try {
|
||||
$resp = Invoke-WebRequest -Uri $uri -Method POST `
|
||||
-Body $body -ContentType 'application/json' `
|
||||
-UseBasicParsing -TimeoutSec $TimeoutSec `
|
||||
-ErrorAction Stop | Out-Null
|
||||
} catch {
|
||||
# Never block imaging on a failed status push. Write to local log only.
|
||||
-ErrorAction Stop
|
||||
try {
|
||||
$logDir = 'C:\Logs'
|
||||
if (-not (Test-Path $logDir)) { New-Item -ItemType Directory -Path $logDir -Force | Out-Null }
|
||||
"$(Get-Date -Format s) Send-PxeStatus failed: $($_.Exception.Message)" |
|
||||
Out-File -FilePath (Join-Path $logDir 'send-pxe-status.log') -Append -Encoding utf8
|
||||
"$(Get-Date -Format s) OK idx=$StageIndex/$StageTotal status=$Status http=$($resp.StatusCode) stage='$Stage'" |
|
||||
Out-File -FilePath $logFile -Append -Encoding utf8
|
||||
} catch { }
|
||||
} catch {
|
||||
try {
|
||||
"$(Get-Date -Format s) ERR idx=$StageIndex/$StageTotal status=$Status uri=$uri stage='$Stage' err=$($_.Exception.Message)" |
|
||||
Out-File -FilePath $logFile -Append -Encoding utf8
|
||||
} catch { }
|
||||
# Never block imaging on a failed status push.
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user