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 19:49:27 -05:00
|
|
|
$computerName=$env:ComputerName
|
2021-06-16 18:18:34 -05:00
|
|
|
$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
|
|
|
|
}
|
|
|
|
|
2021-06-16 20:09:35 -05:00
|
|
|
Write-Output "Checking disks for $($computerName)"
|
|
|
|
|
2021-06-16 18:18:34 -05:00
|
|
|
foreach ($i in $volumes) {
|
2021-06-16 20:00:20 -05:00
|
|
|
if ($i.FileSystemLabel -eq "") {
|
2021-06-16 20:06:29 -05:00
|
|
|
Write-Output ""
|
2021-06-16 18:18:34 -05:00
|
|
|
} else {
|
2021-06-16 20:00:20 -05:00
|
|
|
$result=Repair-Volume -FileSystemLabel $i.FileSystemLabel -Scan
|
|
|
|
|
|
|
|
if ($result.value -gt 0) {
|
|
|
|
Repair-Volume -FileSystemLabel $i.FileSystemLabel -Scan -OfflineScanAndFix
|
|
|
|
$requireReboot = $true
|
|
|
|
} else {
|
2021-06-16 20:05:10 -05:00
|
|
|
Write-Output "$($i.FileSystemLabel): Drive is OK!"
|
|
|
|
Write-Log "$($now), $($i.FileSystemLabel), $($result), $($computerName)"
|
2021-06-16 20:00:20 -05:00
|
|
|
}
|
2021-06-16 18:18:34 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($requireReboot -eq $true) {
|
|
|
|
# TODO: Reboot logic goes here
|
|
|
|
Write-Output "Reboot required!"
|
|
|
|
}
|