How can I set up email alerts for low disk space on a Windows server?

0
6
Asked By PixelGiraffe77 On

I'm looking for the simplest way to get email alerts when my Windows server is running low on disk space. I'm starting to play around with Performance Monitor, but if anyone has a straightforward PowerShell script that can accomplish this, I'd really appreciate it! I want to avoid using third-party applications if possible, but I'm open to recommendations if there's no other way.

4 Answers

Answered By TechieTim42 On

You can also run a PowerShell script regularly that checks the free space and emails you alerts when it drops below a certain percentage. If you're looking for a more robust tool, Netwrix has a free disk space monitoring tool worth checking out. Just set it up to send alerts when the free space gets low!

Answered By CuriousCoder99 On

If you're managing multiple servers, you might want to look into an open-source RMM solution like Netlock RMM. It can handle low disk space alerts among other features, but it does require setting up your server to run it. If you prefer sticking with PowerShell, here's a quick example:

```powershell
$smtpServer = "smtp.yourdomain.com"
$smtpPort = 587
$smtpUser = "[email protected]"
$smtpPass = "yourpassword"
$from = "[email protected]"
$to = "[email protected]"
$subject = "Warning: Hard disk over 90% full"
$threshold = 90

Get-WmiObject Win32_LogicalDisk -Filter "DriveType=3" | ForEach-Object {
$usedPercent = [math]::Round((($_.Size - $_.FreeSpace) / $_.Size) * 100, 2)
if ($usedPercent -ge $threshold) {
$body = "Disk $($_.DeviceID) is $usedPercent% full."
$smtp = New-Object System.Net.Mail.SmtpClient($smtpServer, $smtpPort)
$smtp.EnableSsl = $true
$smtp.Credentials = New-Object System.Net.NetworkCredential($smtpUser, $smtpPass)
$mail = New-Object System.Net.Mail.MailMessage($from, $to, $subject, $body)
$smtp.Send($mail)
}
}
```
This script checks all your drives and sends an alert if any are above the specified threshold.

Answered By NinjaNarwhal22 On

You can use Event Viewer to trigger alerts! Check for Event ID 2013 and create a task associated with that event. This lets you run a PowerShell script or batch file to send an email whenever the disk space hits a certain limit. It’s a pretty simple method and doesn’t involve any extra tools—just your script!

Answered By DataDiva88 On

For those interested in monitoring disk space by actual GB remaining rather than percentage, you can customize your PowerShell script to check free space left in GB. Just convert the bytes to GB, and compare it against your thresholds (like 50GB or 10GB)—definitely doable with some scripting!

PixelGiraffe77 -

Exactly! It's just a matter of tweaking the math in the script to pull the free space in GB instead of a percentage. I’ll definitely give that a shot!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.