- Get-PCProfile: subtype-strip fallback. DODA bays set pc-subtype.txt=doda, so the profile key became "gea-shopfloor-cmm-doda" which matched NO profile/alias -> Get-PCProfile returned null -> callers fell to hardcoded defaults (no PC-DMIS desktop icons; Defect Tracker / WJ Shopfloor / Plant Apps force-started). Now an unmatched compound key falls back to the bare pc-type (-> CMM). VM-tested: gea-shopfloor-cmm/doda + CMM/doda resolve to CMM (7 apps, PC-DMIS present); non-CMM unaffected. - 09-Setup-CMM Step 2.5c: Active Setup seed for goCMM 2.12 DataFolder. goCMM 2.12 stores its shared-data-dir in HKCU\Software\General Electric\goCMM\DataFolder (decompiled: RegistrySettings uses Registry.CurrentUser - per-user). Imaging as SupportUser wouldn't reach the ShopFloor operator's HKCU. Active Setup runs the StubPath once per user at first logon -> every user gets DataFolder=C:\geaofi\. VM-tested: StubPath writes the value with the trailing backslash intact. - Convert-goCMMSettings.ps1: converts legacy goCMM 1.1 ApplicationSettings.xml -> goCMM 2.12 goCMMSettings.xml schema. VM-tested: output byte-identical to a real goCMM-2.12-produced CMM10 goCMMSettings.xml. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
145 lines
6.2 KiB
PowerShell
145 lines
6.2 KiB
PowerShell
# Get-PCProfile.ps1 - Shared helper for resolving the active PC profile
|
|
# from site-config.json. Dot-source this from any script that needs
|
|
# profile-aware configuration:
|
|
#
|
|
# . "$PSScriptRoot\lib\Get-PCProfile.ps1" (from Shopfloor\ scripts)
|
|
# . "$PSScriptRoot\Get-PCProfile.ps1" (from lib\ scripts)
|
|
#
|
|
# After dot-sourcing, these variables are available:
|
|
# $siteConfig - full parsed site-config.json (or $null)
|
|
# $pcType - from pc-type.txt (e.g. "Standard", "CMM", "Display")
|
|
# $pcSubtype - from pc-subtype.txt (e.g. "Timeclock", "Machine", "Lobby")
|
|
# $profileKey - lookup key (e.g. "Standard-Machine", "CMM", "Display-Lobby")
|
|
# $pcProfile - the matched profile object from pcProfiles, or $null
|
|
#
|
|
# Resolution order for any config key (e.g. startupItems):
|
|
# 1. $pcProfile.startupItems (profile-specific override)
|
|
# 2. $siteConfig.startupItems (site-wide default)
|
|
# 3. (hardcoded fallback in the calling script)
|
|
#
|
|
# Usage pattern in consuming scripts:
|
|
# $items = Get-ProfileValue 'startupItems'
|
|
# if ($null -ne $items) { ... } else { <hardcoded fallback> }
|
|
#
|
|
# Get-ProfileValue distinguishes "not set" ($null) from "explicitly empty"
|
|
# (@()) so a profile can opt out of a site-wide default by setting the
|
|
# key to []. Do NOT use truthiness checks like `if ($pcProfile.startupItems)`
|
|
# because an empty array is falsy and would fall through to site defaults.
|
|
|
|
function Get-ProfileValue {
|
|
param([Parameter(Mandatory)][string]$Key)
|
|
if ($pcProfile -and ($pcProfile.PSObject.Properties.Name -contains $Key)) {
|
|
return ,@($pcProfile.$Key)
|
|
}
|
|
if ($siteConfig -and ($siteConfig.PSObject.Properties.Name -contains $Key)) {
|
|
return ,@($siteConfig.$Key)
|
|
}
|
|
return $null
|
|
}
|
|
|
|
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
|
|
|
|
# Read PC type + sub-type from the files startnet.cmd wrote during imaging
|
|
$pcType = ''
|
|
$pcSubtype = ''
|
|
$typeFile = 'C:\Enrollment\pc-type.txt'
|
|
$subtypeFile = 'C:\Enrollment\pc-subtype.txt'
|
|
|
|
if (Test-Path -LiteralPath $typeFile) {
|
|
$pcType = (Get-Content -LiteralPath $typeFile -First 1 -ErrorAction SilentlyContinue).Trim()
|
|
}
|
|
if (Test-Path -LiteralPath $subtypeFile) {
|
|
$pcSubtype = (Get-Content -LiteralPath $subtypeFile -First 1 -ErrorAction SilentlyContinue).Trim()
|
|
}
|
|
|
|
# Display sub-type fallback: if pc-subtype.txt is absent (post-rename-reorg
|
|
# default) but display-type.txt exists, use it as the subtype. Lets the
|
|
# Display-Lobby / Display-Dashboard / gea-shopfloor-display-{lobby,dashboard}
|
|
# profile keys resolve correctly for Display PCs.
|
|
$displayTypeFile = 'C:\Enrollment\display-type.txt'
|
|
if (-not $pcSubtype -and ($pcType -ieq 'gea-shopfloor-display' -or $pcType -ieq 'Display') -and (Test-Path -LiteralPath $displayTypeFile)) {
|
|
$pcSubtype = (Get-Content -LiteralPath $displayTypeFile -First 1 -ErrorAction SilentlyContinue).Trim()
|
|
}
|
|
|
|
# Build the profile key: "Standard-Machine", "CMM", "Display-Lobby", etc.
|
|
$profileKey = if ($pcSubtype) { "$pcType-$pcSubtype" } else { $pcType }
|
|
|
|
# 2026-05-03 rename: when the legacy key (e.g. "Standard-Machine") is not
|
|
# present in pcProfiles, fall through to the new gea-shopfloor-* equivalent
|
|
# (e.g. "gea-shopfloor-collections"). Vice versa: a fleet PC that already
|
|
# writes "gea-shopfloor-collections" finds its profile under either key.
|
|
$pcProfileAliasGroups = @(
|
|
@('Standard-Machine', 'gea-shopfloor-collections', 'gea-shopfloor-nocollections'),
|
|
@('Standard-Timeclock', 'gea-shopfloor-common'),
|
|
@('Lab', 'gea-shopfloor-common'),
|
|
@('CMM', 'gea-shopfloor-cmm'),
|
|
@('Keyence', 'gea-shopfloor-keyence'),
|
|
@('WaxAndTrace', 'gea-shopfloor-waxtrace'),
|
|
@('Genspect', 'gea-shopfloor-genspect'),
|
|
@('Display', 'gea-shopfloor-display'),
|
|
@('Display-Lobby', 'gea-shopfloor-display-Lobby', 'gea-shopfloor-display-lobby'),
|
|
@('Display-Dashboard', 'gea-shopfloor-display-Dashboard', 'gea-shopfloor-display-dashboard'),
|
|
@('Heattreat', 'gea-shopfloor-heattreat')
|
|
)
|
|
|
|
# Look up the profile in pcProfiles. Fall back to $null (callers use
|
|
# site-wide defaults or hardcoded values).
|
|
$pcProfile = $null
|
|
if ($siteConfig -and $siteConfig.pcProfiles -and $profileKey) {
|
|
$pcProfile = $siteConfig.pcProfiles.$profileKey
|
|
if (-not $pcProfile) {
|
|
foreach ($g in $pcProfileAliasGroups) {
|
|
if ($g -icontains $profileKey) {
|
|
foreach ($alias in $g) {
|
|
if ($alias -ieq $profileKey) { continue }
|
|
$candidate = $siteConfig.pcProfiles.$alias
|
|
if ($candidate) { $pcProfile = $candidate; break }
|
|
}
|
|
break
|
|
}
|
|
}
|
|
}
|
|
# Subtype-strip fallback: a compound key like "gea-shopfloor-cmm-doda" (DODA
|
|
# CMM bays set pc-subtype.txt=doda) has no profile of its own. Fall back to
|
|
# the BARE pc-type ("gea-shopfloor-cmm" -> "CMM"). Without this the profile
|
|
# resolves to $null and callers silently use hardcoded defaults (wrong
|
|
# desktop icons + unwanted startup items).
|
|
if (-not $pcProfile -and $pcSubtype) {
|
|
$bare = $pcType
|
|
$pcProfile = $siteConfig.pcProfiles.$bare
|
|
if (-not $pcProfile) {
|
|
foreach ($g in $pcProfileAliasGroups) {
|
|
if ($g -icontains $bare) {
|
|
foreach ($alias in $g) {
|
|
if ($alias -ieq $bare) { continue }
|
|
$candidate = $siteConfig.pcProfiles.$alias
|
|
if ($candidate) { $pcProfile = $candidate; break }
|
|
}
|
|
break
|
|
}
|
|
}
|
|
}
|
|
if ($pcProfile) { $profileKey = $bare }
|
|
}
|
|
}
|
|
|
|
if ($pcProfile) {
|
|
Write-Host "PC profile: $profileKey" -ForegroundColor Cyan
|
|
} elseif ($profileKey) {
|
|
Write-Host "PC profile '$profileKey' not found in site-config.json - using site defaults" -ForegroundColor DarkGray
|
|
}
|