I was reading my last blog post Monitoring disk drives and realized, what if I don’t have a monitoring system? I would want the notifications, right?

Well, of course we want to know if our disk drives are getting full in time.
The quick solution, send email message.

I’m going to create a function and use the function from the Monitoring disk drives as the message to send with the email, so I assume we have already run the function and have it already in our session.

Function Send-EmailNotification {
 param(
  [parameter(Mandatory=$true)]$EmailTo,
  [parameter(Mandatory=$true)]$EmailFrom,
  [parameter(Mandatory=$true)]$SMTP,
  $Port="25",
  [parameter(Mandatory=$true)]$Drives=("C"),
  [parameter(Mandatory=$true)]$Warning,
  [parameter(Mandatory=$true)]$Critical
 )
 
 $Message = Monitor-Drives -Drives $Drives -Warning $Warning -Critical $Critical

 Send-MailMessage -To $EmailTo -From $EmailFrom -SmtpServer $SMTP -Port $Port -Subject "Disk drives are getting full" -Body $Message -BodyAsHtml
}

Run the function with parameters

Send-EmailNotifications -EmailTo halli@powershell.is -EmailFrom ServerName@domain.com -SMTP smtp.domain.com -Port 25 -Drives C,E -Warning 80 -Critical 90

Good to run in a scheduled task and get notifications if your disk drives are getting full and if you happen to not have a monitoring system (I recommend to have a monitoring system :))

That’s it for now, I’m writing this from a hotel on a vacation in Dublin, great city by the way.

Hallgrimur #TheMachine