2
0

Add Check_scripts/Win - Disk drive health.ps1

This commit is contained in:
2023-09-06 15:41:10 +02:00
parent af15ba1aec
commit 436728a434

View File

@@ -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