major logging overhaul, plus other fixes

This commit is contained in:
2020-10-22 14:01:35 -04:00
parent 77cf4d6276
commit 978373ebe2
27 changed files with 430 additions and 611 deletions
+11 -12
View File
@@ -1,29 +1,28 @@
## Run enhanced DISM for Windows 8 and higher endpoints
If ( IsWindowsVersion -ge "6.2" )
{
## The name of the log file for this script
$LogName = "Fix-WindowsHealth"
LogMsg "Fix-WindowsHealth.ps1"
$BeginDISMRun = $(Get-Date).AddSeconds(-1)
## Scan the Windows Component Store for problems
Log "Beginning Windows Component Store scan" $LogName
LogMsg "Beginning Windows Component Store scan"
Start-Process "dism.exe" -ArgumentList "/online /cleanup-image /scanhealth" -Wait
Log "Completed Windows Component Store scan" $LogName
LogMsg "Completed Windows Component Store scan"
## Check to see if the previous command recorded any problems that need repairing
Log "Beginning Windows Component Store health check" $LogName
LogMsg "Beginning Windows Component Store health check"
$CheckHealthOutput = $(dism /online /cleanup-image /checkhealth) | Out-String
If ( $CheckHealthOutput -match "repairable" )
{
Log "Completed Windows Component Store health check: Problems found" $LogName
LogMsg "Completed Windows Component Store health check: Problems found"
## Repair problems with the Windows Component Store
Log "Beginning Windows Component Store restoration" $LogName
LogMsg "Beginning Windows Component Store restoration"
Start-Process "dism.exe" -ArgumentList "/online /cleanup-image /restorehealth" -Wait
Log "Completed Windows Component Store restoration" $LogName
LogMsg "Completed Windows Component Store restoration"
}
Else { Log "Completed Windows Component Store health check: No problems found" $LogName }
Else { LogMsg "Completed Windows Component Store health check: No problems found" }
$EndDISMRun = $(Get-Date).AddSeconds(1)
@@ -31,12 +30,12 @@ If ( IsWindowsVersion -ge "6.2" )
$DISMLogFile = "${MSPLogs}\Fix-WindowsHealth_DISM.log"
If ( Test-Path $DISMLogFile ) { Remove-Item $DISMLogFile -Force }
New-Item -Path $DISMLogFile -ItemType File
Log "Beginning Windows Component Store log data collection" $LogName
LogMsg "Beginning Windows Component Store log data collection"
Get-Content -Path "${Env:WinDir}\Logs\DISM\dism.log" | Select-String -Pattern '^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})' |
% { If ( ((Get-Date $_.Line.Substring(0,19)) -gt $BeginDISMRun) -and ((Get-Date $_.Line.Substring(0,19)) -le $EndDISMRun) ) {
Add-Content -Path $DISMLogFile -Value $_.Line
}
}
Log "Completed Windows Component Store log data collection" $LogName
LogMsg "Completed Windows Component Store log data collection"
}
Else { Log "Online image cleanup and restoration is only supported on Windows 8 and higher" $LogName }
Else { LogMsg "Online image cleanup and restoration is only supported on Windows 8 and higher" }