Files
management-scripts/Fix-WindowsHealth.ps1
T

41 lines
2.0 KiB
PowerShell
Raw Normal View History

2020-09-09 21:06:44 -04:00
## Run enhanced DISM for Windows 8 and higher endpoints
If ( IsWindowsVersion -ge "6.2" )
{
2020-10-22 14:01:35 -04:00
LogMsg "Fix-WindowsHealth.ps1"
2020-09-09 21:06:44 -04:00
$BeginDISMRun = $(Get-Date).AddSeconds(-1)
## Scan the Windows Component Store for problems
2020-10-22 14:01:35 -04:00
LogMsg "Beginning Windows Component Store scan"
2020-09-09 21:06:44 -04:00
Start-Process "dism.exe" -ArgumentList "/online /cleanup-image /scanhealth" -Wait
2020-10-22 14:01:35 -04:00
LogMsg "Completed Windows Component Store scan"
2020-09-09 21:06:44 -04:00
## Check to see if the previous command recorded any problems that need repairing
2020-10-22 14:01:35 -04:00
LogMsg "Beginning Windows Component Store health check"
2020-09-09 21:06:44 -04:00
$CheckHealthOutput = $(dism /online /cleanup-image /checkhealth) | Out-String
If ( $CheckHealthOutput -match "repairable" )
{
2020-10-22 14:01:35 -04:00
LogMsg "Completed Windows Component Store health check: Problems found"
2019-11-11 19:22:39 -05:00
2020-09-09 21:06:44 -04:00
## Repair problems with the Windows Component Store
2020-10-22 14:01:35 -04:00
LogMsg "Beginning Windows Component Store restoration"
2020-09-09 21:06:44 -04:00
Start-Process "dism.exe" -ArgumentList "/online /cleanup-image /restorehealth" -Wait
2020-10-22 14:01:35 -04:00
LogMsg "Completed Windows Component Store restoration"
2019-11-11 19:22:39 -05:00
}
2020-10-22 14:01:35 -04:00
Else { LogMsg "Completed Windows Component Store health check: No problems found" }
2020-09-09 21:06:44 -04:00
$EndDISMRun = $(Get-Date).AddSeconds(1)
## Parse DISM log file for recent activity
$DISMLogFile = "${MSPLogs}\Fix-WindowsHealth_DISM.log"
If ( Test-Path $DISMLogFile ) { Remove-Item $DISMLogFile -Force }
New-Item -Path $DISMLogFile -ItemType File
2020-10-22 14:01:35 -04:00
LogMsg "Beginning Windows Component Store log data collection"
2020-09-09 21:06:44 -04:00
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
2019-11-11 19:22:39 -05:00
}
}
2020-10-22 14:01:35 -04:00
LogMsg "Completed Windows Component Store log data collection"
2019-11-11 19:22:39 -05:00
}
2020-10-22 14:01:35 -04:00
Else { LogMsg "Online image cleanup and restoration is only supported on Windows 8 and higher" }