diff --git a/WindowsMaintenanceReport.ps1 b/WindowsMaintenanceReport.ps1 index eedb911..2a7c22b 100644 --- a/WindowsMaintenanceReport.ps1 +++ b/WindowsMaintenanceReport.ps1 @@ -740,13 +740,36 @@ try { Write-Section $writer 'SYSTEM FILE CHECK - VERIFY ONLY' { if ($isAdmin) { '[RUNNING] sfc.exe /verifyonly' - sfc.exe /verifyonly + + $tempSfc = Join-Path $env:TEMP ( + 'winreport_sfc_' + + [guid]::NewGuid().ToString('N') + + '.txt' + ) + + try { + cmd.exe /c "sfc.exe /verifyonly > `"$tempSfc`" 2>&1" + + if (Test-Path $tempSfc) { + $bytes = [System.IO.File]::ReadAllBytes($tempSfc) + + # SFC output is commonly UTF-16LE + $text = [System.Text.Encoding]::Unicode.GetString($bytes) + + $text.Trim([char]0) + } + else { + 'SFC output file was not created.' + } + } + finally { + Remove-Item $tempSfc -Force -ErrorAction SilentlyContinue + } } else { 'Skipped: sfc /verifyonly requires an elevated session.' } } - Write-Section $writer 'IMPORTANT DIRECTORIES' { $programFilesX86 = [Environment]::GetEnvironmentVariable('ProgramFiles(x86)')