diff --git a/scripts/Bootstrap/Install-AutopilotMonitor-dev.ps1 b/scripts/Bootstrap/Install-AutopilotMonitor-dev.ps1 index cde00d83..030e373f 100644 --- a/scripts/Bootstrap/Install-AutopilotMonitor-dev.ps1 +++ b/scripts/Bootstrap/Install-AutopilotMonitor-dev.ps1 @@ -143,16 +143,21 @@ try { # Collect real (non-special) user profiles as full paths (WMI Special flag + filesystem). $excludePattern = '^(defaultuser\d*|Public|Default( User)?|All Users|WDAGUtilityAccount)$' + # NOTE: the outer @() is required. Without it the trailing Where/Select pipeline + # unwraps a single result back to a scalar string, so $profilePaths[0] would index + # into the string and return its first char ('C') instead of the full path. $profilePaths = @( - try { - Get-CimInstance Win32_UserProfile -ErrorAction Stop | - Where-Object { -not $_.Special -and $_.LocalPath -like 'C:\Users\*' } | - ForEach-Object { $_.LocalPath } - } catch { Write-Log "INFO: WMI profile query failed, continuing with filesystem check." } + @( + try { + Get-CimInstance Win32_UserProfile -ErrorAction Stop | + Where-Object { -not $_.Special -and $_.LocalPath -like 'C:\Users\*' } | + ForEach-Object { $_.LocalPath } + } catch { Write-Log "INFO: WMI profile query failed, continuing with filesystem check." } - (Get-ChildItem 'C:\Users' -Directory -ErrorAction SilentlyContinue).FullName - ) | Where-Object { $_ -and (Split-Path $_ -Leaf) -notmatch $excludePattern } | - Select-Object -Unique + (Get-ChildItem 'C:\Users' -Directory -ErrorAction SilentlyContinue).FullName + ) | Where-Object { $_ -and (Split-Path $_ -Leaf) -notmatch $excludePattern } | + Select-Object -Unique + ) # OOBE-relax: the ONLY exemption to guards 2+3. Matches exactly the Windows Backup for # Organizations restore (one user signs in + restores DURING OOBE). All three must hold: diff --git a/scripts/Bootstrap/Test-ShouldBootstrapAgent-dev.ps1 b/scripts/Bootstrap/Test-ShouldBootstrapAgent-dev.ps1 index 1c71b7d7..706ff49d 100644 --- a/scripts/Bootstrap/Test-ShouldBootstrapAgent-dev.ps1 +++ b/scripts/Bootstrap/Test-ShouldBootstrapAgent-dev.ps1 @@ -78,20 +78,25 @@ if ($deployed) { $excludePattern = '^(defaultuser\d*|Public|Default( User)?|All Users|WDAGUtilityAccount)$' $wmiProfileQueryFailed = $false +# NOTE: the outer @() is required. Without it the trailing Where/Select pipeline +# unwraps a single result back to a scalar string, so $profilePaths[0] would index +# into the string and return its first char ('C') instead of the full path. $profilePaths = @( - try { - Get-CimInstance Win32_UserProfile -ErrorAction Stop | - Where-Object { -not $_.Special -and $_.LocalPath -like 'C:\Users\*' } | - ForEach-Object { $_.LocalPath } - } - catch { - $wmiProfileQueryFailed = $true - } + @( + try { + Get-CimInstance Win32_UserProfile -ErrorAction Stop | + Where-Object { -not $_.Special -and $_.LocalPath -like 'C:\Users\*' } | + ForEach-Object { $_.LocalPath } + } + catch { + $wmiProfileQueryFailed = $true + } - (Get-ChildItem 'C:\Users' -Directory -ErrorAction SilentlyContinue).FullName -) | -Where-Object { $_ -and (Split-Path $_ -Leaf) -notmatch $excludePattern } | -Select-Object -Unique + (Get-ChildItem 'C:\Users' -Directory -ErrorAction SilentlyContinue).FullName + ) | + Where-Object { $_ -and (Split-Path $_ -Leaf) -notmatch $excludePattern } | + Select-Object -Unique +) if ($wmiProfileQueryFailed) { Write-Step -Status 'WARN' -Message 'Profiles: WMI query failed, filesystem check still applied.'