-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-failing-hdd.ps1
36 lines (24 loc) · 1.39 KB
/
check-failing-hdd.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#-------------------------------
# Author Joe Meyrick
# Written 6/17/2020
# Description: Get Hardrive Status that isn't marked as ok, if OK isn't in the status it will send an email report to the designated email
# Potential values: $values = 'Degraded','Error','Lost Comm','No Contact','NonRecover','OK','Pred Fail','Service','Starting','Stopping','Stressed','Unknown'
#--------------------------------
#Paramater for email to so you can specift who gets the report email
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)] [String]$emailTo
)
if ( Get-CimInstance -ClassName Win32_DiskDrive | Select-Object -Property Caption, Status | where-object {$_.Status -ne "OK"} ) {
#Will email the results of report.txt to the email specificed in the emailTo parameter
$Subject = "Poteltial Harddrive Failure $env:ComputerName.$env:USERDNSDOMAIN "
$SMTPServer = "smtp-relay.wharton.upenn.edu"
$EmailFrom = "$env:[email protected]"
$resuts = Get-CimInstance -ClassName Win32_DiskDrive | Select-Object -Property Caption, Status | where-object {$_.Status -ne "OK"} | Out-File -filepath C:\hdd-status.txt
$body = Get-Content -Path C:\hdd-status.txt | Out-String
Send-MailMessage -To $emailTo -From $EmailFrom -Subject "$subject" -Body $body -SmtpServer $SMTPserver
#clean up old results
Remove-Item C:\hdd-status.txt
} else {
Write-Host 'nothing found'
}