fix scrubber call
This commit is contained in:
@@ -34,8 +34,12 @@ function Get-OfficeDeploymentDefinitions {
|
||||
ManualScrubUrl = 'https://learn.microsoft.com/en-us/troubleshoot/microsoft-365/admin/miscellaneous/get-help-office-uninstall'
|
||||
GetHelpUrl = 'https://aka.ms/SaRA_EnterpriseVersionFiles'
|
||||
GetHelpExecutable = 'GetHelpCmd.exe'
|
||||
ScrubArguments = '-S OfficeScrubScenario -AcceptEula -OfficeVersion All'
|
||||
# The current GetHelpCmd build rejects -OfficeVersion, despite the older
|
||||
# scenario documentation listing it. Use the tool's own supported example.
|
||||
ScrubArguments = '-S OfficeScrubScenario -AcceptEula'
|
||||
ScrubRecoveryExitCodes = @(17002, 17004)
|
||||
ScrubDiagnosticLineLimit = 20
|
||||
ScrubDiagnosticLineCharacters = 2000
|
||||
HelperVersion = 'EmberkomOfficeUserCleanup-v5'
|
||||
Language = 'en-us'
|
||||
OfficeBuildPattern = '^16\.0\.\d+\.\d+$'
|
||||
@@ -906,17 +910,47 @@ function Initialize-OfficeScrubMedia {
|
||||
$executables[0].FullName
|
||||
}
|
||||
|
||||
function Read-OfficeScrubOutput {
|
||||
param([string]$LogPrefix)
|
||||
$definitions = Get-OfficeDeploymentDefinitions
|
||||
$output = @()
|
||||
foreach ($stream in @('stdout', 'stderr')) {
|
||||
$path = "$LogPrefix.$stream.log"
|
||||
$file = Get-Item -LiteralPath $path -ErrorAction Stop
|
||||
[string]$content = Get-Content -LiteralPath $path -Raw -ErrorAction Stop
|
||||
$null = Write-Output "Get Help ${stream}: $($file.Length) bytes in $path"
|
||||
if ([string]::IsNullOrWhiteSpace($content)) { $null = Write-Output "Get Help ${stream}: no text captured." }
|
||||
else {
|
||||
$lines = @($content -split '\r?\n' | Where-Object { ![string]::IsNullOrWhiteSpace($_) })
|
||||
if ($lines.Count -gt $definitions.ScrubDiagnosticLineLimit) {
|
||||
# Usage failures put the reason first and examples last. Preserve both.
|
||||
$headCount = [int][Math]::Floor($definitions.ScrubDiagnosticLineLimit / 2)
|
||||
$lines = @($lines | Select-Object -First $headCount) + @('[middle output omitted; see full stream log]') + @($lines | Select-Object -Last ($definitions.ScrubDiagnosticLineLimit - $headCount))
|
||||
}
|
||||
foreach ($line in $lines) {
|
||||
if ($line.Length -gt $definitions.ScrubDiagnosticLineCharacters) { $line = $line.Substring(0, $definitions.ScrubDiagnosticLineCharacters) + ' [truncated; see full stream log]' }
|
||||
$null = Write-Output "Get Help ${stream} detail: $line"
|
||||
}
|
||||
}
|
||||
$output += $content
|
||||
}
|
||||
$output -join "`n"
|
||||
}
|
||||
|
||||
function Invoke-OfficeScrubRecovery {
|
||||
param($Media, [string]$Workspace, [string]$Reason)
|
||||
if ($Media.ScrubAttempted) { throw 'Office scrub recovery was already attempted. Installation stopped; no repeated scrub or install loop will run.' }
|
||||
$Media | Add-Member -NotePropertyName ScrubAttempted -NotePropertyValue $true -Force
|
||||
$Media | Add-Member -NotePropertyName ScrubReason -NotePropertyValue $Reason -Force
|
||||
$null = Write-Output "Office scrub recovery selected: $Reason"
|
||||
$null = Write-Output 'Running one Microsoft Get Help OfficeScrubScenario attempt. It removes all Office versions, including Visio/Project. Get Help may display a child window despite the hidden launch.'
|
||||
$null = Write-Output 'Running one Microsoft Get Help OfficeScrubScenario attempt for detected Office installations. All Office registrations must be gone before replacement installation. Get Help may display a child window despite the hidden launch.'
|
||||
$scrubber = Initialize-OfficeScrubMedia $Workspace
|
||||
$prefix = Join-Path $Workspace 'office-scrub'
|
||||
$code = Invoke-OfficeProcess $scrubber (Get-OfficeDeploymentDefinitions).ScrubArguments $prefix
|
||||
$output = (Get-Content -LiteralPath "$prefix.stdout.log" -Raw -ErrorAction Stop) + "`n" + (Get-Content -LiteralPath "$prefix.stderr.log" -Raw -ErrorAction Stop)
|
||||
$output = Read-OfficeScrubOutput $prefix
|
||||
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."
|
||||
}
|
||||
$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