Set-MachineNumber: handle duplicate-PC reassignment (real -> real)
Tech catches a PC imaged with a wrong machine number. Previously the share restore (NTLARS .reg + UDC settings + UDC live data) only fired on the placeholder->real transition, so a real->real change rewrote only UDC JSON, eDNC reg, and MTConnect Devices.xml - leaving the wrong NTLARS config in place. Update-MachineNumber.ps1: replace the placeholder-only guard with an any-change guard so the share restore block fires on reassign too. The existing one-shot migrated/ consumption keeps live-data restore idempotent. Also writes C:\Enrollment\machine-number.txt to keep imaging-time scripts in sync. Set-MachineNumber.ps1 (both collections + nocollections): show a confirmation dialog when reassigning between two real numbers, naming old/new and listing what gets pulled. Audit each call to C:\Logs\Shopfloor\reassign.log. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -56,8 +56,52 @@ if ($new -notmatch '^\d+$') {
|
||||
exit 1
|
||||
}
|
||||
|
||||
# --- Reassign confirmation (real -> real). Placeholder (9999/null) skips. ---
|
||||
$currentIsReal = (($currentUdc -and $currentUdc -ne '9999') -or
|
||||
($currentEdnc -and $currentEdnc -ne '9999'))
|
||||
$differsFromNew = ($currentUdc -ne $new) -or ($currentEdnc -ne $new)
|
||||
if ($currentIsReal -and $differsFromNew) {
|
||||
$oldDisplay = if ($currentUdc) { $currentUdc } else { $currentEdnc }
|
||||
$confirmMsg = @(
|
||||
"Reassign machine number from $oldDisplay to $new ?"
|
||||
""
|
||||
"This will pull from the SFLD share for $new :"
|
||||
" - NTLARS .reg backup (eFocas / PPDCS / Hssb)"
|
||||
" - UDC settings (udc_settings_$new.json)"
|
||||
" - UDC live data backup (if present)"
|
||||
""
|
||||
"Use this only when the PC was imaged with the wrong number."
|
||||
) -join "`n"
|
||||
$confirm = [System.Windows.Forms.MessageBox]::Show(
|
||||
$confirmMsg,
|
||||
"Confirm Reassignment",
|
||||
[System.Windows.Forms.MessageBoxButtons]::OKCancel,
|
||||
[System.Windows.Forms.MessageBoxIcon]::Warning
|
||||
)
|
||||
if ($confirm -ne [System.Windows.Forms.DialogResult]::OK) {
|
||||
Write-Host "Reassignment cancelled."
|
||||
exit 0
|
||||
}
|
||||
}
|
||||
|
||||
$mnResult = Update-MachineNumber -NewNumber $new -Site $site
|
||||
|
||||
# --- Audit log: one line per machine-number change. Best-effort. ---
|
||||
try {
|
||||
$logDir = 'C:\Logs\Shopfloor'
|
||||
if (-not (Test-Path $logDir)) { New-Item -ItemType Directory -Path $logDir -Force | Out-Null }
|
||||
$logFile = Join-Path $logDir 'reassign.log'
|
||||
$now = (Get-Date).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ')
|
||||
$whoami = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
|
||||
$oldDisp = if ($mnResult.OldUdc) { $mnResult.OldUdc } elseif ($mnResult.OldEdnc) { $mnResult.OldEdnc } else { '(none)' }
|
||||
$regFlag = if ($mnResult.RegImported) { 'OK' } else { 'skip' }
|
||||
$udcFlag = if ($mnResult.UdcSettingsRestored) { 'OK' } else { 'skip' }
|
||||
$dataFlag = if ($mnResult.UdcRestored) { 'OK' } else { 'skip' }
|
||||
$mtcCnt = @($mnResult.MTConnectUpdated).Count
|
||||
$line = "$now $env:COMPUTERNAME user=$whoami $oldDisp -> $new udc=$($mnResult.UdcUpdated) ednc=$($mnResult.EdncUpdated) reg=$regFlag settings=$udcFlag data=$dataFlag mtc=$mtcCnt"
|
||||
Add-Content -Path $logFile -Value $line -Encoding UTF8
|
||||
} catch {}
|
||||
|
||||
$results = @()
|
||||
if ($mnResult.UdcUpdated) {
|
||||
Write-Host "UDC: $currentUdc -> $new"
|
||||
|
||||
Reference in New Issue
Block a user