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:
@@ -18,46 +18,15 @@
|
||||
Add-Type -AssemblyName Microsoft.VisualBasic
|
||||
Add-Type -AssemblyName System.Windows.Forms
|
||||
|
||||
function Get-SiteConfig {
|
||||
$configPath = 'C:\Enrollment\site-config.json'
|
||||
if (-not (Test-Path -LiteralPath $configPath)) {
|
||||
Write-Host "site-config.json not found - using defaults" -ForegroundColor DarkGray
|
||||
return $null
|
||||
}
|
||||
try {
|
||||
return (Get-Content -LiteralPath $configPath -Raw -ErrorAction Stop | ConvertFrom-Json)
|
||||
} catch {
|
||||
Write-Warning "Failed to parse site-config.json: $_"
|
||||
return $null
|
||||
}
|
||||
}
|
||||
$siteConfig = Get-SiteConfig
|
||||
. "$PSScriptRoot\..\Shopfloor\lib\Get-PCProfile.ps1"
|
||||
. "$PSScriptRoot\..\Shopfloor\lib\Update-MachineNumber.ps1"
|
||||
|
||||
$udcSettingsPath = "C:\ProgramData\UDC\udc_settings.json"
|
||||
$udcExePath = "C:\Program Files\UDC\UDC.exe"
|
||||
$ednRegPath = "HKLM:\SOFTWARE\WOW6432Node\GE Aircraft Engines\DNC\General"
|
||||
$site = if ($siteConfig) { $siteConfig.siteName } else { 'West Jefferson' }
|
||||
$site = if ($siteConfig) { $siteConfig.siteName } else { 'West Jefferson' }
|
||||
|
||||
# --- Read current values for display ---
|
||||
$currentUdc = $null
|
||||
$currentEdnc = $null
|
||||
|
||||
if (Test-Path $udcSettingsPath) {
|
||||
try {
|
||||
$json = Get-Content $udcSettingsPath -Raw | ConvertFrom-Json
|
||||
$currentUdc = $json.GeneralSettings.MachineNumber
|
||||
} catch {
|
||||
$currentUdc = "(unreadable: $_)"
|
||||
}
|
||||
}
|
||||
|
||||
if (Test-Path $ednRegPath) {
|
||||
try {
|
||||
$currentEdnc = (Get-ItemProperty -Path $ednRegPath -Name MachineNo -ErrorAction Stop).MachineNo
|
||||
} catch {
|
||||
$currentEdnc = $null
|
||||
}
|
||||
}
|
||||
$currentMN = Get-CurrentMachineNumber
|
||||
$currentUdc = $currentMN.Udc
|
||||
$currentEdnc = $currentMN.Ednc
|
||||
|
||||
# --- Show prompt with current state ---
|
||||
$promptLines = @()
|
||||
@@ -87,66 +56,28 @@ if ($new -notmatch '^\d+$') {
|
||||
exit 1
|
||||
}
|
||||
|
||||
$mnResult = Update-MachineNumber -NewNumber $new -Site $site
|
||||
|
||||
$results = @()
|
||||
|
||||
# --- 1. Stop UDC.exe before editing its JSON (avoid stale shutdown write) ---
|
||||
$udcProcs = Get-Process UDC -ErrorAction SilentlyContinue
|
||||
if ($udcProcs) {
|
||||
Write-Host "Stopping UDC.exe ($($udcProcs.Count) instance(s))..."
|
||||
$udcProcs | ForEach-Object {
|
||||
try {
|
||||
$_.Kill()
|
||||
$_.WaitForExit(5000) | Out-Null
|
||||
} catch {
|
||||
Write-Warning "Failed to stop UDC.exe (PID $($_.Id)): $_"
|
||||
}
|
||||
}
|
||||
Start-Sleep -Seconds 1
|
||||
}
|
||||
|
||||
# --- 2. Update UDC settings JSON ---
|
||||
if (Test-Path $udcSettingsPath) {
|
||||
try {
|
||||
$json = Get-Content $udcSettingsPath -Raw | ConvertFrom-Json
|
||||
$json.GeneralSettings.MachineNumber = $new
|
||||
$json | ConvertTo-Json -Depth 99 | Set-Content -Path $udcSettingsPath -Encoding UTF8
|
||||
Write-Host "UDC: $currentUdc -> $new"
|
||||
$results += "UDC updated to $new"
|
||||
} catch {
|
||||
Write-Warning "Failed to update UDC settings: $_"
|
||||
$results += "UDC FAILED: $_"
|
||||
}
|
||||
} else {
|
||||
Write-Warning "UDC settings file not found at $udcSettingsPath. Run UDC.exe at least once to initialize."
|
||||
if ($mnResult.UdcUpdated) {
|
||||
Write-Host "UDC: $currentUdc -> $new"
|
||||
$results += "UDC updated to $new"
|
||||
} elseif (-not (Test-Path 'C:\ProgramData\UDC\udc_settings.json')) {
|
||||
$results += "UDC: settings file missing (run UDC.exe once first)"
|
||||
}
|
||||
|
||||
# --- 3. Update eDNC MachineNo registry value ---
|
||||
if (Test-Path $ednRegPath) {
|
||||
try {
|
||||
Set-ItemProperty -Path $ednRegPath -Name MachineNo -Value $new -Type String -Force
|
||||
Write-Host "eDNC: $currentEdnc -> $new"
|
||||
$results += "eDNC updated to $new"
|
||||
} catch {
|
||||
Write-Warning "Failed to update eDNC MachineNo: $_"
|
||||
$results += "eDNC FAILED: $_"
|
||||
}
|
||||
} else {
|
||||
Write-Warning "eDNC registry key not found at $ednRegPath. Is eDNC installed?"
|
||||
if ($mnResult.EdncUpdated) {
|
||||
Write-Host "eDNC: $currentEdnc -> $new"
|
||||
$results += "eDNC updated to $new"
|
||||
} elseif (-not (Test-Path 'HKLM:\SOFTWARE\WOW6432Node\GE Aircraft Engines\DNC\General')) {
|
||||
$results += "eDNC: registry key missing (eDNC not installed?)"
|
||||
}
|
||||
|
||||
# --- 4. Relaunch UDC.exe with new args (if installed) ---
|
||||
if (Test-Path $udcExePath) {
|
||||
try {
|
||||
Start-Process -FilePath $udcExePath -ArgumentList @("-site", "`"$site`"", "-machine", $new)
|
||||
Write-Host "UDC.exe relaunched."
|
||||
} catch {
|
||||
Write-Warning "Failed to relaunch UDC.exe: $_"
|
||||
}
|
||||
foreach ($err in $mnResult.Errors) {
|
||||
Write-Warning $err
|
||||
$results += $err
|
||||
}
|
||||
if ($mnResult.UdcUpdated) { Write-Host "UDC.exe relaunched." }
|
||||
|
||||
# --- 5. Show summary ---
|
||||
# --- Show summary ---
|
||||
$summary = ($results -join "`n") + "`n`nTo apply eDNC changes, restart any running DncMain.exe."
|
||||
[System.Windows.Forms.MessageBox]::Show(
|
||||
$summary,
|
||||
|
||||
Reference in New Issue
Block a user