a94c203added a RunSynchronous Path of 417 chars to both std/eng answer files. Windows caps it at 259 and then rejects the WHOLE answer file, so an Engineer build stopped at 'Windows could not parse or process unattend answer file'. The live files were restored to their pre-a94c203 versions the same day. - The status steps now fit: Send-ImagingStage.ps1 -Persist copies itself out of C:\Deploy (no cmd copy chain), short PowerShell switches, default arguments left out. Longest Path is 168 chars; lint-unattend passes. NOT deployed: these files must go live only through deploy-unattend.sh. - scripts/deploy-unattend.sh: the only route for an answer file to a PXE server. Lints first and refuses on any error, backs up, swaps atomically, lints the live copy and restores the backup if that fails. - .githooks/pre-commit (git config core.hooksPath .githooks): refuses a commit whose staged unattend fails the linter. Verified by planting a 352-char Path (blocked) and against the exacta94c203file (rejected). - Boot menu: also accept SecureBoot read as hex 01, and show the raw values in the warning so a wrong read can be diagnosed from the screen.
86 lines
3.4 KiB
PowerShell
86 lines
3.4 KiB
PowerShell
# Send-ImagingStage.ps1 - posts one progress step of a gea-standard /
|
|
# gea-engineer build to the PXE webapp's /imaging/status endpoint, so the
|
|
# imaging floor follows these builds past WinPE (the shopfloor build has its
|
|
# own reporting in Shopfloor\lib\Send-PxeStatus.ps1).
|
|
#
|
|
# Called from the image's FlatUnattendW10.xml (specialize RunSynchronous and
|
|
# oobeSystem FirstLogonCommands). Keep those command lines short: Windows
|
|
# rejects the whole unattend if a RunSynchronous Path exceeds 259 characters
|
|
# (check with scripts/lint-unattend.py --local). Deployed to
|
|
# _shared\Applications\extra\pxe-status\ on the PXE server, which PESetup
|
|
# copies to C:\Deploy\Applications\extra\pxe-status\.
|
|
#
|
|
# Best-effort: never blocks or fails Windows setup. Every error is swallowed,
|
|
# the script always exits 0, and each attempt is logged to
|
|
# C:\Logs\send-imaging-stage.log.
|
|
|
|
param(
|
|
[Parameter(Mandatory = $true)][string]$Stage,
|
|
[int]$StageIndex = 0,
|
|
[int]$StageTotal = 5,
|
|
[string]$PCType = '',
|
|
[ValidateSet('in_progress', 'succeeded', 'failed')][string]$Status = 'in_progress',
|
|
[string]$PxeServer = '172.16.9.1',
|
|
[int]$Port = 9009,
|
|
[int]$TimeoutSec = 5,
|
|
# Copy this script to C:\ProgramData\PxeStatus first: the bulk-enrollment
|
|
# task deletes C:\Deploy before first logon, when the later steps run.
|
|
[switch]$Persist
|
|
)
|
|
|
|
$logFile = 'C:\Logs\send-imaging-stage.log'
|
|
function Log([string]$msg) {
|
|
try {
|
|
if (-not (Test-Path 'C:\Logs')) { New-Item -ItemType Directory -Path 'C:\Logs' -Force | Out-Null }
|
|
"$(Get-Date -Format s) $msg" | Out-File -FilePath $logFile -Append -Encoding utf8
|
|
} catch { }
|
|
}
|
|
|
|
if ($Persist) {
|
|
try {
|
|
New-Item -ItemType Directory -Path 'C:\ProgramData\PxeStatus' -Force | Out-Null
|
|
Copy-Item -LiteralPath $PSCommandPath -Destination 'C:\ProgramData\PxeStatus\Send-ImagingStage.ps1' -Force
|
|
} catch { Log "persist failed: $($_.Exception.Message)" }
|
|
}
|
|
|
|
try {
|
|
$serial = $null
|
|
try { $serial = (Get-CimInstance -ClassName Win32_BIOS -ErrorAction Stop).SerialNumber } catch {
|
|
try { $serial = (Get-WmiObject -Class Win32_BIOS -ErrorAction Stop).SerialNumber } catch { }
|
|
}
|
|
if ([string]::IsNullOrWhiteSpace($serial)) { $serial = $env:COMPUTERNAME }
|
|
$serial = ($serial -as [string]).Trim()
|
|
|
|
$mac = $null
|
|
try {
|
|
$nic = Get-NetAdapter -Physical -ErrorAction Stop |
|
|
Where-Object { $_.Status -eq 'Up' -and $_.MediaType -eq '802.3' } | Select-Object -First 1
|
|
if ($nic) { $mac = $nic.MacAddress -replace '-', ':' }
|
|
} catch { }
|
|
|
|
$payload = @{
|
|
serial = $serial
|
|
hostname_target = $env:COMPUTERNAME
|
|
current_stage = $Stage
|
|
stage_index = $StageIndex
|
|
stage_total = $StageTotal
|
|
status = $Status
|
|
}
|
|
if ($PCType) { $payload.pctype = $PCType }
|
|
if ($mac) { $payload.mac = $mac }
|
|
$body = $payload | ConvertTo-Json -Compress
|
|
$uri = "http://${PxeServer}:${Port}/imaging/status"
|
|
|
|
try {
|
|
$resp = Invoke-WebRequest -Uri $uri -Method POST -Body $body -ContentType 'application/json' `
|
|
-UseBasicParsing -TimeoutSec $TimeoutSec -ErrorAction Stop
|
|
Log "OK $($resp.StatusCode) $body"
|
|
} catch {
|
|
# Off the imaging network (or the server is down): nothing to report to.
|
|
Log "FAIL $($_.Exception.Message) $body"
|
|
}
|
|
} catch {
|
|
Log "ERROR $($_.Exception.Message)"
|
|
}
|
|
exit 0
|