Shared machine-number helper, site-config for OpenText + PreInstall, placeholder type dirs
Three optimization batches from the pipeline audit:
1. Shared Update-MachineNumber.ps1 helper (lib/)
Extracts duplicated machine-number update logic from Configure-PC.ps1,
Check-MachineNumber.ps1, and Set-MachineNumber.ps1 into a shared
dot-sourceable helper at Shopfloor/lib/Update-MachineNumber.ps1.
Exports:
Get-CurrentMachineNumber → @{ Udc = $string; Ednc = $string }
Update-MachineNumber -NewNumber <n> [-Site <s>] → @{ UdcUpdated; EdncUpdated; Errors }
All three consumers now dot-source the helper instead of duplicating
~50 lines each. Set-MachineNumber.ps1 also migrated from inline
Get-SiteConfig to dot-sourcing Get-PCProfile.ps1 for consistency.
2. Site-config integration for remaining scripts
Setup-OpenText.ps1: exclude lists (profiles + shortcuts) now read from
site-config.json opentext section, falling back to West Jefferson
defaults. Inline Get-SiteConfig since the script runs from
C:\PreInstall\installers\opentext\ (can't dot-source Get-PCProfile).
00-PreInstall-MachineApps.ps1: after parsing preinstall.json, scans
InstallArgs for "West Jefferson" and replaces with site-config
siteName if different. Inline Get-SiteConfig for same reason.
3. Placeholder type-specific directories
Created skeleton 01-Setup-*.ps1 scripts for all PC types so the
directory structure is in place and Run-ShopfloorSetup's type-specific
loop has something to iterate over:
Genspect/01-Setup-Genspect.ps1
Keyence/01-Setup-Keyence.ps1
WaxAndTrace/01-Setup-WaxAndTrace.ps1
Lab/01-Setup-Lab.ps1
Each logs a "no type-specific apps configured yet" banner and exits.
Fill in app installs when details are finalized; for share-based
installs, copy the CMM/01-Setup-CMM.ps1 pattern.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -17,6 +17,19 @@ $installerDir = Join-Path $preInstallDir "installers"
|
||||
$logDir = "C:\Logs\PreInstall"
|
||||
$logFile = Join-Path $logDir "install.log"
|
||||
|
||||
# --- Inline site-config reader (same pattern as Setup-OpenText.ps1; this script
|
||||
# runs from C:\Enrollment\shopfloor-setup\Shopfloor\ but Get-PCProfile.ps1 may
|
||||
# not be available yet, so keep the lookup self-contained) ---
|
||||
function Get-SiteConfig {
|
||||
$configPath = 'C:\Enrollment\site-config.json'
|
||||
if (-not (Test-Path $configPath)) { return $null }
|
||||
try {
|
||||
return Get-Content $configPath -Raw | ConvertFrom-Json
|
||||
} catch {
|
||||
return $null
|
||||
}
|
||||
}
|
||||
|
||||
# --- Setup logging ---
|
||||
# IMPORTANT: do NOT wipe the log on each run. The runner can get killed by an
|
||||
# installer-triggered reboot mid-execution. On the next autologon, the dispatcher
|
||||
@@ -102,6 +115,20 @@ if (-not $config.Applications) {
|
||||
Write-PreInstallLog "Staged installer dir: $installerDir"
|
||||
Write-PreInstallLog "Found $($config.Applications.Count) app entries in preinstall.json"
|
||||
|
||||
# --- Site-name override: replace "West Jefferson" in InstallArgs if site-config says otherwise ---
|
||||
$siteConfig = Get-SiteConfig
|
||||
if ($siteConfig -and $siteConfig.siteName -and $siteConfig.siteName -ne 'West Jefferson') {
|
||||
Write-PreInstallLog "Site config loaded - siteName: $($siteConfig.siteName)"
|
||||
foreach ($app in $config.Applications) {
|
||||
if ($app.InstallArgs -and $app.InstallArgs -match 'West Jefferson') {
|
||||
$app.InstallArgs = $app.InstallArgs -replace 'West Jefferson', $siteConfig.siteName
|
||||
Write-PreInstallLog " Overrode site name in $($app.Name) args: $($app.InstallArgs)"
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Write-PreInstallLog "No site-config override for siteName (using defaults in preinstall.json)"
|
||||
}
|
||||
|
||||
# --- Detection helper (mirrors Simple-Install.ps1's Test-ApplicationInstalled) ---
|
||||
function Test-AppInstalled {
|
||||
param($App)
|
||||
|
||||
Reference in New Issue
Block a user