diff --git a/playbook/shopfloor-setup/common/GE-Enforce.ps1 b/playbook/shopfloor-setup/common/GE-Enforce.ps1 index 36b0f2c..cfbad6f 100644 --- a/playbook/shopfloor-setup/common/GE-Enforce.ps1 +++ b/playbook/shopfloor-setup/common/GE-Enforce.ps1 @@ -236,10 +236,19 @@ try { # continues if the share path is not writable. # ------------------------------------------------------------------ try { + # Re-mount W: before status write-back. Long-running entries (UDC + # WaitTimeoutSec=120) can let the SMB session time out idle, leaving + # W: as a dead drive letter that fails downstream Path operations + # with confusing "argument is null" errors. Cheap to re-attach. + & net use $driveLetter /delete /y 2>$null | Out-Null + & net use $driveLetter $shopfloorShareRoot /user:$($cred.Username) $($cred.Password) /persistent:no 2>&1 | Out-Null + # Live NetBIOS name from kernel - not $env:COMPUTERNAME, which is # cached in the process env block and goes stale after a post-image # rename on Intune-managed PCs. $hostname = [System.Environment]::MachineName + if (-not $hostname) { $hostname = 'UNKNOWN' } + if (-not $driveLetter) { throw 'driveLetter unset before status write-back' } $statusDir = Join-Path (Join-Path $driveLetter '_outputs') (Join-Path 'logs' $hostname) if (-not (Test-Path $statusDir)) { New-Item -Path $statusDir -ItemType Directory -Force -ErrorAction Stop | Out-Null