From 2b322ae06222991ecdfad6fb2410ad684834de2c Mon Sep 17 00:00:00 2001 From: "Wyatt J. Miller" Date: Wed, 16 Jun 2021 19:18:34 -0400 Subject: [PATCH] init commit --- README.md | 0 disk_check.ps1 | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 README.md create mode 100644 disk_check.ps1 diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/disk_check.ps1 b/disk_check.ps1 new file mode 100644 index 0000000..81df99d --- /dev/null +++ b/disk_check.ps1 @@ -0,0 +1,37 @@ +# 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' +$cimSession=New-Session $computerName +$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) { + $result=Repair-Volumes -CimSession $cimSession -FileSystemLabel $v.FileSystemLabel -Scan + + 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!" +}