more fixes for the scrubber
This commit is contained in:
@@ -379,7 +379,8 @@ function Clear-OfficePreviousDeploymentFiles {
|
||||
$roots = @(Get-OfficeDeploymentRoots)
|
||||
$processes = @(Get-CimInstance Win32_Process -ErrorAction Stop)
|
||||
foreach ($root in $roots) {
|
||||
if (Test-OfficeStagingInUse $root $processes) { throw "A surviving installer is running. Stop the previous deployment before removing old artifacts in $root." }
|
||||
$blocking = @(Get-OfficeBlockingProcesses $root $processes)
|
||||
if ($blocking.Count) { throw "A surviving installer is running: $(($blocking | ForEach-Object { "$($_.Name) (PID $($_.ProcessId))" }) -join '; '). Resolve the previous deployment before removing old artifacts in $root. GetHelpElevated Run.ps1 can remain at a 'Press any key to exit' prompt after success or failure; inspect its final report before dismissing it." }
|
||||
Assert-OfficeManagedPath $root (Join-Path $root 'path-check')
|
||||
}
|
||||
$tasks = @(Get-ScheduledTask -ErrorAction Stop | Where-Object { $_.TaskName -match '^Emberkom-OfficeCleanup-[a-f0-9]{32}-S-1-[\d-]+$' })
|
||||
@@ -410,18 +411,25 @@ function Clear-OfficePreviousDeploymentFiles {
|
||||
}
|
||||
}
|
||||
|
||||
function Test-OfficeStagingInUse {
|
||||
function Get-OfficeBlockingProcesses {
|
||||
param([string]$Workspace, [object[]]$Processes)
|
||||
# Be conservative even when a child installer no longer names its source folder.
|
||||
foreach ($process in $Processes) {
|
||||
if ($process.Name -in @('setup.exe', 'odt.exe', 'msiexec.exe', 'OfficeC2RClient.exe', 'GetHelpCmd.exe', 'SaRAcmd.exe', 'teamsbootstrapper.exe', 'OutlookSetup.exe', 'OneDriveSetup.exe', 'MicrosoftEdgeWebview2Setup.exe')) { return $true }
|
||||
if ($process.Name -eq 'OfficeClickToRun.exe' -and $process.CommandLine -notmatch '(?i)\s/(service|user)\s*$') { return $true }
|
||||
if ($process.CommandLine -match '(?i)\b(OffScrub[^\s"\\/]*\.(vbs|ps1)|OfficeScrubScenario)\b') { return $true }
|
||||
if ($process.Name -in @('setup.exe', 'odt.exe', 'msiexec.exe', 'OfficeC2RClient.exe', 'GetHelpCmd.exe', 'SaRAcmd.exe', 'teamsbootstrapper.exe', 'OutlookSetup.exe', 'OneDriveSetup.exe', 'MicrosoftEdgeWebview2Setup.exe')) { $process; continue }
|
||||
if ($process.Name -eq 'OfficeClickToRun.exe' -and $process.CommandLine -notmatch '(?i)\s/(service|user)\s*$') { $process; continue }
|
||||
if ($process.CommandLine -match '(?i)\b(OffScrub[^\s"\\/]*\.(vbs|ps1)|OfficeScrubScenario)\b') { $process; continue }
|
||||
# Current Get Help detaches PowerShell into its own temp directory. Its
|
||||
# command line contains neither OfficeScrubScenario nor our workspace.
|
||||
if ($process.CommandLine -match '(?i)[\\/]GetHelpElevated[\\/][^\\/"\s]+[\\/]Run\.ps1(?:["\s]|$)') { $process; continue }
|
||||
foreach ($value in @($process.CommandLine, $process.ExecutablePath)) {
|
||||
if ($value -and $value.IndexOf($Workspace, [StringComparison]::OrdinalIgnoreCase) -ge 0) { return $true }
|
||||
if ($Workspace -and $value -and $value.IndexOf($Workspace, [StringComparison]::OrdinalIgnoreCase) -ge 0) { $process; break }
|
||||
}
|
||||
}
|
||||
return $false
|
||||
}
|
||||
|
||||
function Test-OfficeStagingInUse {
|
||||
param([string]$Workspace, [object[]]$Processes)
|
||||
return @(Get-OfficeBlockingProcesses $Workspace $Processes).Count -gt 0
|
||||
}
|
||||
|
||||
function Complete-OfficeDeploymentFiles {
|
||||
@@ -951,6 +959,18 @@ function Invoke-OfficeScrubRecovery {
|
||||
if ($output -match '(?im)^\s*(Error:\s*)?Invalid command line arguments\b|^\s*Usage:\s*GetHelpCmd\.exe\b') {
|
||||
throw "Get Help rejected its command line and printed usage (process $code). No scrub success was reported. Arguments: $((Get-OfficeDeploymentDefinitions).ScrubArguments). See Get Help stdout/stderr details in the management log and $prefix.stdout.log."
|
||||
}
|
||||
if ($output -match '(?im)^\s*ExecutionResultDetails:\s*Uninstall office is running in the background\.') {
|
||||
# This is a launch acknowledgement, not an uninstall result. The observed
|
||||
# GetHelpElevated Run.ps1 waits in Console.ReadKey in finally after BOTH
|
||||
# success and failure. Neither launcher exit 0 nor worker lifetime proves
|
||||
# removal, and a missing product registration can predate a corrupt scrub.
|
||||
$workers = @(Get-OfficeBlockingProcesses $Workspace @(Get-CimInstance Win32_Process -ErrorAction Stop))
|
||||
foreach ($worker in $workers) {
|
||||
$null = Write-Output "Get Help background worker: $($worker.Name), PID $($worker.ProcessId), created $($worker.CreationDate). Command: $($worker.CommandLine)"
|
||||
}
|
||||
$workerSummary = if ($workers.Count) { ($workers | ForEach-Object { "$($_.Name) (PID $($_.ProcessId))" }) -join '; ' } else { 'none observed; absence does not establish success' }
|
||||
throw "Get Help background removal requires attended verification (launcher exit $code; workers: $workerSummary). Get Help acknowledged launching removal, not its completion. Its GetHelpElevated Run.ps1 can wait at 'Press any key to exit' after success OR failure. Check the worker console/final diagnostic report, complete or dismiss it, and verify removal before rerunning. Installation stopped; active workers block media cleanup and new deployment. See $prefix.stdout.log."
|
||||
}
|
||||
$results = @([regex]::Matches($output, '(?m)^\s*(\d{2}):') | ForEach-Object { $_.Groups[1].Value })
|
||||
$null = Write-Output "Get Help scrub result: process $code; scenario results $($results -join ', '). Logs: $prefix"
|
||||
# 66/68 mean Office was not found, not a verified repair of damaged state.
|
||||
|
||||
Reference in New Issue
Block a user