tacticalrmm/scripts/Win_Disk_Status.ps1

20 lines
786 B
PowerShell
Raw Normal View History

2021-01-10 17:33:48 +00:00
# Checks local disks for errors reported in event viewer within the last 24 hours
2021-04-10 17:22:54 +00:00
$ErrorActionPreference = 'silentlycontinue'
2021-01-10 17:33:48 +00:00
$TimeSpan = (Get-Date) - (New-TimeSpan -Day 1)
2021-04-10 17:22:54 +00:00
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*)
2021-01-10 17:33:48 +00:00
{
2021-04-10 17:22:54 +00:00
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
2021-01-10 17:33:48 +00:00
}
2021-04-10 17:22:54 +00:00
else {
Write-Output "Disks are Healthy"
exit 0
2021-01-10 17:33:48 +00:00
}
Exit $LASTEXITCODE