DiskCheck/disk_check.ps1
2021-06-16 20:46:52 -04:00

41 lines
959 B
PowerShell

# 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.txt"
$computerName='localhost'
$rebootTime=Get-Date "1:00"
$requireReboot=$false
$volumes=Get-Volume
Function Write-Log{
Param ([string]$logstring)
if (-not(Test-Path -Path $logFile -PathType Leaf)) {
New-Item -ItemType File -Path $logFile -Force
}
Add-Content $logFile -value $logstring
}
foreach ($i in $volumes) {
$result=Repair-Volume -FileSystemLabel $i.FileSystemLabel -Scan
if ($result.value -gt 0) {
Repair-Volume -FileSystemLabel $i.FileSystemLabel -Scan -OfflineScanAndFix
$requireReboot = $true
} else {
Write-Output $i.FileSystemLabel + ": Drive is OK!"
Write-Log $now + ',' + $i.FileSystemLabel + ',' + $result + ',' + $targetComputer
}
}
if ($requireReboot -eq $true) {
# TODO: Reboot logic goes here
Write-Output "Reboot required!"
}