diff --git a/Fix-WindowsHealth.ps1 b/Fix-WindowsHealth.ps1 index 87b5328..aa4496c 100644 --- a/Fix-WindowsHealth.ps1 +++ b/Fix-WindowsHealth.ps1 @@ -21,16 +21,22 @@ Switch ( $SFCOutput ) { } # Run enhanced DISM for Windows 8 and higher endpoints +$DISMRun = $false If ( IsWindowsVersion -ge "6.2" ) { # Record start of DISM repair $BeginDISMRun = (Get-Date) - Write-Output "Beginning repair of Windows Component Store" - Start-Process "dism.exe" -ArgumentList "/online /cleanup-image /restorehealth" -Wait + Try { + Write-Output "Beginning repair of Windows Component Store" + Start-Process "dism.exe" -ArgumentList "/online /cleanup-image /restorehealth" -Wait - Write-Output "Beginning cleanup of superceded components in Windows Component Store" - Start-Process "dism.exe" -ArgumentList "/online /cleanup-image /startcomponentcleanup" -Wait + Write-Output "Beginning cleanup of superceded components in Windows Component Store" + Start-Process "dism.exe" -ArgumentList "/online /cleanup-image /startcomponentcleanup" -Wait + + $DISMRun = $true + } + Catch { Write-Error $_.Exception.Message } # Record end of DISM repair $EndDISMRun = (Get-Date) @@ -56,4 +62,7 @@ If ( $ScheduleCheckDisk ) { } Else { New-TicketComment -Comment "Disk check was not scheduled to run, as no Windows integrity violations were found." -Hidden -DoNotEmail New-TicketComment -Comment "Your computer has been repaired. Please restart as soon as you're able." -} \ No newline at end of file +} + +# Bill ticket if action was taken +If ( $DISMRun -or $ScheduleCheckDisk ) { New-TicketTimerEntry -Comment "Corruption was found and has been repaired." } \ No newline at end of file