From 3cef681bbc64a6a20039e1d2ffb4f44c53e67706 Mon Sep 17 00:00:00 2001 From: "Wyatt J. Miller" Date: Mon, 5 Jul 2021 18:03:25 -0400 Subject: [PATCH] eliminated disk checking errors --- disk_check.ps1 | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/disk_check.ps1 b/disk_check.ps1 index 0751f9b..b556413 100644 --- a/disk_check.ps1 +++ b/disk_check.ps1 @@ -22,20 +22,49 @@ Function Write-Log{ Add-Content $logFile -value $logstring } +# function to scan the disk whether we have to use a drive letter +# (i.e. C:, D:, etc) or a filesystem label (i.e. Windows, etc.) +Function Scan-Disk{ + Param ([string]$volume_identifier) + + $result=Repair-Volume -DriveLetter $i.DriveLetter -Scan + + if ($result.value -gt 0) { + Repair-Volume -DriveLetter $i.DriveLetter -Scan -OfflineScanAndFix + $requireReboot = $true + } else { + Write-Output "$($i.FileSystemLabel): Drive is OK!" + Write-Log "Date: $($now), Drive Letter: $($i.DriveLetter), Volume Name: $($i.FileSystemLabel), Result: $($result), $($computerName)" + } +} + Write-Output "Checking disks for $($computerName)" foreach ($i in $volumes) { - if ($i.FileSystemLabel -eq "") { - Write-Output "" - } else { + if ($i.FileSystemLabel -eq $null) { $result=Repair-Volume -DriveLetter $i.DriveLetter -Scan if ($result.value -gt 0) { Repair-Volume -DriveLetter $i.DriveLetter -Scan -OfflineScanAndFix $requireReboot = $true + } else { + Write-Output "$($i.DriveLetter): Drive is OK!" + Write-Log "Date: $($now), Drive Letter: $($i.DriveLetter), Result: $($result), $($computerName)" + } + } else { + if ($i.DriveLetter -eq $null) { + Write-Output "Volume is not identifiable! Skipping..." + continue + } + + $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 "Date: $($now), Drive Letter: $($i.DriveLetter), Volume Name: $($i.FileSystemLabel), Result: $($result), $($computerName)" + Write-Log "Date: $($now), Volume Name: $($i.FileSystemLabel), Result: $($result), $($computerName)" } } }