2021-06-16 18:18:34 -05:00
|
|
|
# DiskCheck PS script
|
|
|
|
# Checking a target computer for hard drive failures
|
|
|
|
#
|
|
|
|
# Written by Wyatt J. Miller
|
|
|
|
# Licensed by Mozilla Public License v2
|
|
|
|
# 2021
|
|
|
|
#
|
|
|
|
|
|
|
|
$logFile="C:\ACS\disk_check.log"
|
|
|
|
$computerName='localhost'
|
2021-06-16 19:09:49 -05:00
|
|
|
$cimSession=New-PSSession $computerName
|
2021-06-16 18:18:34 -05:00
|
|
|
$rebootTime=Get-Date "1:00"
|
|
|
|
$requireReboot=$false
|
|
|
|
$volumes=Get-Volumes -CimSession $cimSession
|
|
|
|
|
|
|
|
Function Write-Log{
|
|
|
|
Param ([string]$logstring)
|
|
|
|
|
|
|
|
Add-Content $logFile -value $logstring
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($i in $volumes) {
|
2021-06-16 19:09:49 -05:00
|
|
|
$result=Repair-Volume -CimSession $cimSession -FileSystemLabel $v.FileSystemLabel -Scan
|
2021-06-16 18:18:34 -05:00
|
|
|
|
|
|
|
if ($result.value -gt 0) {
|
|
|
|
Repair-Volume -CimSession $cimSession -FileSystemLabel $v.FileSystemLabel -Scan -OfflineScanAndFix
|
|
|
|
$requireReboot = $true
|
|
|
|
} else {
|
|
|
|
Write-Output "$(v.FileSystemLabel): Drive is OK!"
|
|
|
|
Write-Log $now + ',' + $volume.FileSystemLabel + ',' + $result + ',' + $targetComputer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($requireReboot -eq $true) {
|
|
|
|
# TODO: Reboot logic goes here
|
|
|
|
Write-Output "Reboot required!"
|
|
|
|
}
|