diff --git a/disk_check.ps1 b/disk_check.ps1 index b556413..f2faeef 100644 --- a/disk_check.ps1 +++ b/disk_check.ps1 @@ -72,4 +72,23 @@ foreach ($i in $volumes) { if ($requireReboot -eq $true) { # TODO: Reboot logic goes here Write-Output "Reboot required!" + + do + { + Write-Output 'Sleeping while waiting for time window' + Write-Output 'Current Time:' + $now.TimeOfDay + $now = Get-Date + Start-Sleep -s 1200 #20 Minutes (1200 Seconds) + } + while ($now.TimeOfDay -gt $earliestRebootTime.TimeOfDay -and $now.TimeOfDay -lt $latestRebootTime.TimeOfDay) + + + #Reboot PC with Faulty Disk for Offline Repair + Restart-Computer -ComputerName $target -Force -Delay -Wait + + #Wait for Reboot and Scan PC with Faulty Disk + $result = Repair-Volume CimSession $cimSession -FileSystemLabel $volume.FileSystemLabel -Scan + + #Report Un-Repairable Disks + Write-Log $now +','+ $result + ',' + $targetComputer, +',' + 'Unable to repair' }