From 436728a434132c36682ba78fdca3d04f9abed051 Mon Sep 17 00:00:00 2001 From: Danny de Kooker Date: Wed, 6 Sep 2023 15:41:10 +0200 Subject: [PATCH] Add Check_scripts/Win - Disk drive health.ps1 --- Check_scripts/Win - Disk drive health.ps1 | 44 +++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Check_scripts/Win - Disk drive health.ps1 diff --git a/Check_scripts/Win - Disk drive health.ps1 b/Check_scripts/Win - Disk drive health.ps1 new file mode 100644 index 0000000..f5b06ba --- /dev/null +++ b/Check_scripts/Win - Disk drive health.ps1 @@ -0,0 +1,44 @@ +<# + .SYNOPSIS + Check the status of the fysical drives (if any) on the system + + .DESCRIPTION + This script will check if there are any error on the disks and will let you know if you need to investigate any errors, + This script should be deployed as a Check Script. + + By default the script will check upto 1 day back in the log, + If you adjust the $Timespan parameter you can extend this by more days. + + .OUTPUTS + This script will report back if it found any of the event logs on the machine with the message of that log entry. + + Errorcodes: + 0 - All OK + 1 - Disk errors detected please investigate + + .EXAMPLE + Win - Disk drive health.ps1 + + .NOTES + Source: Tactical RMM repository + + .CHANGELOG + 24-06-2022 - Copied from TRMM repo, tweaked for my own environment. +#> + +#region Parameters, functions and global variables + $ErrorActionPreference = 'silentlycontinue' + $TimeSpan = (Get-Date) - (New-TimeSpan -Day 1) +#endregion +#region script + if (Get-WinEvent -FilterHashtable @{LogName = 'system'; ID = '11', '9', '15', '52', '129', '7', '98'; Level = 2, 3; ProviderName = '*disk*', '*storsvc*', '*ntfs*'; StartTime = $TimeSpan } -MaxEvents 10 | Where-Object -Property Message -Match Volume*) { + Write-Output "Disk errors detected please investigate" + Get-WinEvent -FilterHashtable @{LogName = 'system'; ID = '11', '9', '15', '52', '129', '7', '98'; Level = 2, 3; ProviderName = '*disk*', '*storsvc*', '*ntfs*'; StartTime = $TimeSpan } + exit 1 + } + else { + Write-Output "Disks are Healthy" + exit 0 + } + Exit $LASTEXITCODE +#endregion \ No newline at end of file