# resolve-bay-config.ps1 - WinPE-runnable bay-config resolver. # # Reads bay-config.csv (per-asset ftpak_version + model + user_id) and # writes the matched row into per-field text files under $OutDir, so the # rest of startnet.cmd + the post-imaging 09-Setup-WaxAndTrace.ps1 can # read them as single-line files (cheaper than re-parsing CSV in batch). # # Outputs (under $OutDir, default W:\Enrollment\waxtrace\): # version.txt - exact FormTracePak version (matches an installer ISO label) # model.txt - sub-version (AVANT / CV-4500 / CV-3200) # userid.txt - per-bay license USER ID # bay-info.txt - human-readable audit dump (timestamped) # # Exit codes: # 0 - row found + files written # 1 - asset_tag not in bay-config.csv (Wax/Trace install will abort cleanly) # 2 - bay-config.csv missing or unparseable [CmdletBinding()] param( [Parameter(Mandatory=$true)][string]$Asset, [string]$ConfigCsv = '', [string]$OutDir = 'W:\Enrollment\waxtrace' ) # Default ConfigCsv: bay-config.csv next to this script on the share OR # under the script's own directory in the local C:\WaxTrace-Install\ tree # (depending on where the caller invokes us from). if (-not $ConfigCsv) { $cands = @( (Join-Path $PSScriptRoot 'bay-config.csv'), (Join-Path $PSScriptRoot '..\bay-config.csv'), 'Y:\installers-post\waxtrace\bay-config.csv', 'C:\WaxTrace-Install\bay-config.csv' ) foreach ($c in $cands) { if (Test-Path -LiteralPath $c) { $ConfigCsv = $c; break } } } if (-not (Test-Path -LiteralPath $ConfigCsv)) { Write-Warning "bay-config.csv not found (looked under $PSScriptRoot, ..\, Y:\installers-post\waxtrace\, C:\WaxTrace-Install\)" exit 2 } Write-Host "resolve-bay-config.ps1: looking up '$Asset' in $ConfigCsv" try { $rows = @(Import-Csv -LiteralPath $ConfigCsv) } catch { Write-Warning "Failed to parse ${ConfigCsv}: $_" exit 2 } $row = $rows | Where-Object { $_.asset_tag -ieq $Asset } | Select-Object -First 1 if (-not $row) { Write-Warning "Asset '$Asset' not in $ConfigCsv. Available asset_tags: $(($rows.asset_tag | Sort-Object) -join ', ')" exit 1 } if (-not (Test-Path -LiteralPath $OutDir)) { New-Item -ItemType Directory -Path $OutDir -Force | Out-Null } function Write-Line { param([string]$Name, [string]$Value) $p = Join-Path $OutDir $Name Set-Content -LiteralPath $p -Value $Value -NoNewline -Force Write-Host " wrote $p = '$Value'" } Write-Line 'version.txt' $row.ftpak_version Write-Line 'model.txt' $row.model Write-Line 'userid.txt' $row.user_id $infoLines = @( "Bay-config resolved at $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')", " Asset: $($row.asset_tag)", " FormTracePak: V$($row.ftpak_version)", " Sub-version: $($row.model)", " USER ID: $($row.user_id)", "", "Source: $ConfigCsv" ) $infoPath = Join-Path $OutDir 'bay-info.txt' Set-Content -LiteralPath $infoPath -Value ($infoLines -join "`r`n") -Force Write-Host " wrote $infoPath" Write-Host "resolve-bay-config.ps1: OK" exit 0