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:
@@ -20,46 +20,19 @@ try { Start-Transcript -Path $transcriptPath -Append -Force | Out-Null } catch {
|
||||
Write-Host "Check-MachineNumber.ps1 starting $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')"
|
||||
Write-Host "Running as: $([System.Security.Principal.WindowsIdentity]::GetCurrent().Name)"
|
||||
|
||||
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\lib\Get-PCProfile.ps1"
|
||||
. "$PSScriptRoot\lib\Update-MachineNumber.ps1"
|
||||
|
||||
Add-Type -AssemblyName Microsoft.VisualBasic
|
||||
Add-Type -AssemblyName System.Windows.Forms
|
||||
|
||||
$taskName = 'Check Machine Number'
|
||||
$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' }
|
||||
$taskName = 'Check Machine Number'
|
||||
$site = if ($siteConfig) { $siteConfig.siteName } else { 'West Jefferson' }
|
||||
|
||||
# --- Read current values ---
|
||||
$currentUdc = $null
|
||||
$currentEdnc = $null
|
||||
|
||||
if (Test-Path $udcSettingsPath) {
|
||||
try {
|
||||
$json = Get-Content $udcSettingsPath -Raw | ConvertFrom-Json
|
||||
$currentUdc = $json.GeneralSettings.MachineNumber
|
||||
} catch {}
|
||||
}
|
||||
|
||||
if (Test-Path $ednRegPath) {
|
||||
try {
|
||||
$currentEdnc = (Get-ItemProperty -Path $ednRegPath -Name MachineNo -ErrorAction Stop).MachineNo
|
||||
} catch {}
|
||||
}
|
||||
$currentMN = Get-CurrentMachineNumber
|
||||
$currentUdc = $currentMN.Udc
|
||||
$currentEdnc = $currentMN.Ednc
|
||||
|
||||
# --- Check if placeholder ---
|
||||
Write-Host "UDC machine number: $(if ($currentUdc) { $currentUdc } else { '(not found)' })"
|
||||
@@ -111,41 +84,13 @@ if ($new -notmatch '^\d+$') {
|
||||
exit 0
|
||||
}
|
||||
|
||||
# --- Update UDC ---
|
||||
# --- Update via shared helper ---
|
||||
$mnResult = Update-MachineNumber -NewNumber $new -Site $site
|
||||
|
||||
$results = @()
|
||||
if (Test-Path $udcSettingsPath) {
|
||||
# Stop UDC first
|
||||
Get-Process UDC -ErrorAction SilentlyContinue | ForEach-Object {
|
||||
try { $_.Kill(); $_.WaitForExit(5000) | Out-Null } catch {}
|
||||
}
|
||||
Start-Sleep -Seconds 1
|
||||
|
||||
try {
|
||||
$json = Get-Content $udcSettingsPath -Raw | ConvertFrom-Json
|
||||
$json.GeneralSettings.MachineNumber = $new
|
||||
$json | ConvertTo-Json -Depth 99 | Set-Content -Path $udcSettingsPath -Encoding UTF8
|
||||
$results += "UDC updated to $new"
|
||||
} catch {
|
||||
$results += "UDC FAILED: $_"
|
||||
}
|
||||
}
|
||||
|
||||
# --- Update eDNC ---
|
||||
if (Test-Path $ednRegPath) {
|
||||
try {
|
||||
Set-ItemProperty -Path $ednRegPath -Name MachineNo -Value $new -Type String -Force
|
||||
$results += "eDNC updated to $new"
|
||||
} catch {
|
||||
$results += "eDNC FAILED: $_"
|
||||
}
|
||||
}
|
||||
|
||||
# --- Relaunch UDC ---
|
||||
if (Test-Path $udcExePath) {
|
||||
try {
|
||||
Start-Process -FilePath $udcExePath -ArgumentList @('-site', "`"$site`"", '-machine', $new)
|
||||
} catch {}
|
||||
}
|
||||
if ($mnResult.UdcUpdated) { $results += "UDC updated to $new" }
|
||||
if ($mnResult.EdncUpdated) { $results += "eDNC updated to $new" }
|
||||
foreach ($err in $mnResult.Errors) { $results += $err -replace '^', 'FAILED: ' }
|
||||
|
||||
# --- Show result ---
|
||||
$summary = ($results -join "`n") + "`n`nTo apply eDNC changes, restart any running DncMain.exe."
|
||||
|
||||
Reference in New Issue
Block a user