From 966d8ccda12c785f740cef0ffd4a6ce86a7cc785 Mon Sep 17 00:00:00 2001 From: "Wyatt J. Miller" Date: Wed, 16 Jun 2021 20:43:11 -0400 Subject: [PATCH] fixes galore --- disk_check.ps1 | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/disk_check.ps1 b/disk_check.ps1 index 719faed..a20ccd7 100644 --- a/disk_check.ps1 +++ b/disk_check.ps1 @@ -6,7 +6,7 @@ # 2021 # -$logFile="C:\ACS\disk_check.log" +$logFile="C:\ACS\disk_check.txt" $computerName='localhost' $rebootTime=Get-Date "1:00" $requireReboot=$false @@ -15,18 +15,22 @@ $volumes=Get-Volumes -CimSession $cimSession Function Write-Log{ Param ([string]$logstring) + if (-not(Test-Path -Path $logFile -PathType Leaf)) { + Add-Item -ItemType File -Path $logFile -Force + } + Add-Content $logFile -value $logstring } foreach ($i in $volumes) { - $result=Repair-Volume -FileSystemLabel $v.FileSystemLabel -Scan + $result=Repair-Volume -FileSystemLabel $i.FileSystemLabel -Scan if ($result.value -gt 0) { - Repair-Volume -FileSystemLabel $v.FileSystemLabel -Scan -OfflineScanAndFix + Repair-Volume -FileSystemLabel $i.FileSystemLabel -Scan -OfflineScanAndFix $requireReboot = $true } else { - Write-Output "$(v.FileSystemLabel): Drive is OK!" - Write-Log $now + ',' + $volume.FileSystemLabel + ',' + $result + ',' + $targetComputer + Write-Output "$(i.FileSystemLabel): Drive is OK!" + Write-Log $now + ',' + $i.FileSystemLabel + ',' + $result + ',' + $targetComputer } }