The picker was reading unit_serial and probe_part from the old INDEX.csv format. bay-config.csv uses different column names (ftpak_version, model, host). Updated Select-Object and display format to match. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
103 lines
3.5 KiB
PowerShell
103 lines
3.5 KiB
PowerShell
# select-waxtrace-asset.ps1 - Arrow-key bay picker for wax/trace imaging.
|
|
#
|
|
# Reads the calibration INDEX.csv on the PXE share to build the menu of known
|
|
# bays. Operator picks with Up/Down arrows + Enter. Always appends an
|
|
# "Other (new bay)" option at the end for bays that don't have a cal ISO yet -
|
|
# selecting it falls back to a free-text prompt.
|
|
#
|
|
# Writes the chosen asset tag to $OutFile (one line, no trailing newline).
|
|
# startnet.cmd reads that file back into the MACHINENUM batch var.
|
|
#
|
|
# Runs in WinPE PowerShell. Win10/11 WinPE ships powershell.exe with
|
|
# System.Console.ReadKey support. Tested 2026-05-18.
|
|
#
|
|
# Exit codes:
|
|
# 0 = asset tag written to $OutFile
|
|
# 1 = user cancelled (Esc) - $OutFile not written
|
|
# 2 = INDEX.csv unreadable AND no fallback entered
|
|
|
|
param(
|
|
[string]$IndexPath = 'Y:\installers-post\waxtrace\calibrations\INDEX.csv',
|
|
[Parameter(Mandatory=$true)][string]$OutFile
|
|
)
|
|
|
|
$ErrorActionPreference = 'Continue'
|
|
|
|
function Read-BayList {
|
|
param([string]$Path)
|
|
if (-not (Test-Path -LiteralPath $Path)) { return @() }
|
|
try {
|
|
return Import-Csv -LiteralPath $Path |
|
|
Select-Object -Property asset_tag, ftpak_version, model, host |
|
|
Sort-Object -Property asset_tag -Descending
|
|
} catch {
|
|
return @()
|
|
}
|
|
}
|
|
|
|
function Show-Menu {
|
|
param(
|
|
[object[]]$Items,
|
|
[int]$Selected,
|
|
[string]$Title
|
|
)
|
|
Clear-Host
|
|
Write-Host ""
|
|
Write-Host " ========================================"
|
|
Write-Host " $Title"
|
|
Write-Host " ========================================"
|
|
Write-Host ""
|
|
Write-Host " Up / Down arrows = navigate, Enter = select, Esc = cancel"
|
|
Write-Host ""
|
|
for ($i = 0; $i -lt $Items.Count; $i++) {
|
|
$item = $Items[$i]
|
|
$line = if ($item -is [string]) { $item } else { "{0,-10} v{1,-6} {2,-10} {3}" -f $item.asset_tag, $item.ftpak_version, $item.model, $item.host }
|
|
if ($i -eq $Selected) {
|
|
Write-Host (" > " + $line) -ForegroundColor Black -BackgroundColor White
|
|
} else {
|
|
Write-Host (" " + $line)
|
|
}
|
|
}
|
|
Write-Host ""
|
|
}
|
|
|
|
$bays = @(Read-BayList -Path $IndexPath)
|
|
$menuItems = @()
|
|
foreach ($b in $bays) { $menuItems += $b }
|
|
$menuItems += '** Other (new bay - enter asset tag manually) **'
|
|
|
|
$sel = 0
|
|
while ($true) {
|
|
Show-Menu -Items $menuItems -Selected $sel -Title "Wax/Trace Asset Tag"
|
|
$key = [System.Console]::ReadKey($true)
|
|
switch ($key.Key) {
|
|
'UpArrow' { if ($sel -gt 0) { $sel-- } }
|
|
'DownArrow' { if ($sel -lt ($menuItems.Count - 1)) { $sel++ } }
|
|
'Enter' {
|
|
if ($sel -eq ($menuItems.Count - 1)) {
|
|
# Manual entry
|
|
Write-Host ""
|
|
$manual = Read-Host " Enter asset tag (e.g. WJRP9999) or blank to abort"
|
|
if ($manual) {
|
|
$manual = $manual.Trim().ToUpper()
|
|
Set-Content -LiteralPath $OutFile -Value $manual -NoNewline -Encoding ascii
|
|
Write-Host ""
|
|
Write-Host " Saved asset tag: $manual"
|
|
Start-Sleep -Seconds 1
|
|
exit 0
|
|
} else {
|
|
exit 1
|
|
}
|
|
} else {
|
|
$pick = $bays[$sel].asset_tag
|
|
Set-Content -LiteralPath $OutFile -Value $pick -NoNewline -Encoding ascii
|
|
Write-Host ""
|
|
Write-Host " Selected: $pick"
|
|
Start-Sleep -Seconds 1
|
|
exit 0
|
|
}
|
|
}
|
|
'Escape' { exit 1 }
|
|
}
|
|
}
|