DiskCheck/disk_check.ps1

41 lines
959 B
PowerShell
Raw Normal View History

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