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>
104 lines
3.6 KiB
PowerShell
104 lines
3.6 KiB
PowerShell
# Update-MachineNumber.ps1 - Shared helper for reading and updating the
|
|
# machine number in UDC and eDNC. Dot-source from any script that needs
|
|
# machine-number operations:
|
|
#
|
|
# . "$PSScriptRoot\lib\Update-MachineNumber.ps1" (from Shopfloor\ scripts)
|
|
# . "$PSScriptRoot\..\Shopfloor\lib\Update-MachineNumber.ps1" (from Standard\ scripts)
|
|
# . "$PSScriptRoot\Update-MachineNumber.ps1" (from lib\ scripts)
|
|
#
|
|
# Exported functions:
|
|
# Get-CurrentMachineNumber - returns @{ Udc = $string_or_null; Ednc = $string_or_null }
|
|
# Update-MachineNumber - updates both, returns @{ UdcUpdated = $bool; EdncUpdated = $bool; Errors = @() }
|
|
#
|
|
# Both handle missing files/keys gracefully (app not installed = skip, not error).
|
|
|
|
$script:UdcSettingsPath = 'C:\ProgramData\UDC\udc_settings.json'
|
|
$script:UdcExePath = 'C:\Program Files\UDC\UDC.exe'
|
|
$script:EdncRegPath = 'HKLM:\SOFTWARE\WOW6432Node\GE Aircraft Engines\DNC\General'
|
|
|
|
function Get-CurrentMachineNumber {
|
|
<#
|
|
.SYNOPSIS
|
|
Reads the current machine number from UDC settings JSON and eDNC registry.
|
|
.OUTPUTS
|
|
Hashtable with keys Udc ($string or $null) and Ednc ($string or $null).
|
|
#>
|
|
$result = @{ Udc = $null; Ednc = $null }
|
|
|
|
if (Test-Path $script:UdcSettingsPath) {
|
|
try {
|
|
$json = Get-Content $script:UdcSettingsPath -Raw | ConvertFrom-Json
|
|
$result.Udc = $json.GeneralSettings.MachineNumber
|
|
} catch {}
|
|
}
|
|
|
|
if (Test-Path $script:EdncRegPath) {
|
|
try {
|
|
$result.Ednc = (Get-ItemProperty -Path $script:EdncRegPath -Name MachineNo -ErrorAction Stop).MachineNo
|
|
} catch {}
|
|
}
|
|
|
|
return $result
|
|
}
|
|
|
|
function Update-MachineNumber {
|
|
<#
|
|
.SYNOPSIS
|
|
Updates UDC + eDNC machine number in one step. Stops UDC before writing,
|
|
relaunches after.
|
|
.PARAMETER NewNumber
|
|
The new machine number (digits only - caller validates).
|
|
.PARAMETER Site
|
|
Site name passed to UDC.exe -site argument. Defaults to 'West Jefferson'.
|
|
.OUTPUTS
|
|
Hashtable: @{ UdcUpdated = $bool; EdncUpdated = $bool; Errors = @() }
|
|
#>
|
|
param(
|
|
[Parameter(Mandatory)]
|
|
[string]$NewNumber,
|
|
|
|
[string]$Site = 'West Jefferson'
|
|
)
|
|
|
|
$out = @{ UdcUpdated = $false; EdncUpdated = $false; Errors = @() }
|
|
|
|
# --- Stop UDC before editing its JSON (avoid stale shutdown write) ---
|
|
Get-Process UDC -ErrorAction SilentlyContinue | ForEach-Object {
|
|
try { $_.Kill(); $_.WaitForExit(5000) | Out-Null } catch {}
|
|
}
|
|
Start-Sleep -Seconds 1
|
|
|
|
# --- Update UDC settings JSON ---
|
|
if (Test-Path $script:UdcSettingsPath) {
|
|
try {
|
|
$json = Get-Content $script:UdcSettingsPath -Raw | ConvertFrom-Json
|
|
$json.GeneralSettings.MachineNumber = $NewNumber
|
|
$json | ConvertTo-Json -Depth 99 | Set-Content -Path $script:UdcSettingsPath -Encoding UTF8
|
|
$out.UdcUpdated = $true
|
|
} catch {
|
|
$out.Errors += "UDC update failed: $_"
|
|
}
|
|
}
|
|
|
|
# --- Update eDNC registry ---
|
|
if (Test-Path $script:EdncRegPath) {
|
|
try {
|
|
Set-ItemProperty -Path $script:EdncRegPath -Name MachineNo -Value $NewNumber -Type String -Force
|
|
$out.EdncUpdated = $true
|
|
} catch {
|
|
$out.Errors += "eDNC update failed: $_"
|
|
}
|
|
}
|
|
|
|
# --- Relaunch UDC with new args ---
|
|
if ((Test-Path $script:UdcExePath) -and $out.UdcUpdated) {
|
|
try {
|
|
Start-Process -FilePath $script:UdcExePath -ArgumentList @('-site', "`"$Site`"", '-machine', $NewNumber)
|
|
} catch {
|
|
$out.Errors += "UDC relaunch failed: $_"
|
|
}
|
|
}
|
|
|
|
return $out
|
|
}
|