I was wondering if there is an easy way to trigger an e-mail alert on Windows Server 2008 when any logical disk partitions become low on space. I have 2 SQL servers that have come close to running out of disk space because of the DB log files.
Thanks, Ryan
One simple way to get Windows Server 2008 to send low disk space e-mail alerts is to use Task Scheduler and the System Log. If the free space falls below the percentage specified in HKLM\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters\DiskSpaceThreshold, an event is recorded in the System Log that can trigger a task to send an e-mail message.
I added disk space monitoring via snmp to my (separate) nagios instance.
Why don't you run a powershell script as a schedule task every day? If the script find the free space of the disk is lower than 10%, it will send you an email or notification.
here is an example code for checking the free space of the disks:
Get-Content ForEach-Object { $; Get-WMIObject –computername $ Win32_LogicalDisk -filter "DriveType=3" | ForEach-Object { $.DeviceID; $.FreeSpace/1GB } }
Both examples do not work because of incorrect PowerShell syntax. The following code lists the volume sizes of the current host (using PowerShell 5.0):
The following code lists the volume sizes of hosts listed in server.txt:
Sidenote
Note that the outer place holder
$_
enumerates the server addresses whereas the inner place holder$_
enumerates the devices. That's a frequent gotcha for PowerShell newbies. If you wanted to use the server address in the inner loop, you'd have to assign it to a new variable in the outer loop.The forum software used here is flawed. In post previews, it displays
$_
correctly as a$_
even if not escaped as code. But the final post removes the underscore, thus making the PowerShell examples incorrect.You can use this script to send an email using your email server. Just replace the name of smtp server name with that of your server. If on the same machine then use "localhost" (smtp server must be functional). The script is found here as well: https://gallery.technet.microsoft.com/scriptcenter/Disk-Space-Report-Reports-98e64d65
After the script is saved in local drive, it can be easily run using powershell and tested. Once script seems to work fine, then it can be scheduled to run everyday or every hour based on requirement using windows task scheduler. This article explains how to run a script using task scheduler. https://www.metalogix.com/help/Content%20Matrix%20Console/SharePoint%20Edition/002_HowTo/004_SharePointActions/012_SchedulingPowerShell.htm
I have fixed the script. Just create a text file named for example server.txt and include the ip address or servernames and then you can execute the following script
Get-Content server.txt | foreach-object{Get-WmiObject -ComputerName 192.168.22.208 win32_logicalDisk -filter "DriveType=3"|ForEach-Object{$.DeviceID; $.FreeSpace/1GB}}
Regards, Luis.
Get-Content server.txt | foreach-object{Get-WmiObject -ComputerName xx.xx.xx.xx win32_logicalDisk -filter "DriveType=3" | forEach-Object{$.DeviceID; $.FreeSpace/1GB}}