Setting Low Disk Space Alerts on Windows Server 2008

90,062

Solution 1

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.

  1. Open Task Scheduler and create a new task.
  2. Enter a name for the task, select "Run whether user is logged on or not", and check "Do not store password."
  3. Add a new trigger on the Triggers tab.
  4. Select "On an event" in the "Begin the task" box.
  5. Set Log to "System", Source to "srv", and Event ID to "2013".
  6. Add a new action on the Actions tab.
  7. Set Action to "Send an e-mail" and fill in the rest of the settings appropriately.
  8. To configure when the low disk space event is recorded in the System Log, open the Registry Editor, navigate to HKLM\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters and add a DWORD value named “DiskSpaceThreshold”, setting it to the desired percentage. When the entry does not exist, the default value is 10.

Solution 2

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):

Get-WmiObject win32_logicalDisk -filter "DriveType=3" | %{ $_.DeviceID; $_.FreeSpace/1GB }

The following code lists the volume sizes of hosts listed in server.txt:

Get-Content server.txt | %{ Get-WMIObject –computername $_ Win32_LogicalDisk -filter "DriveType=3" | %{ $_.DeviceID; $_.FreeSpace/1GB } }

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.

Solution 3

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 } }

Solution 4

I added disk space monitoring via snmp to my (separate) nagios instance.

Share:
90,062

Related videos on Youtube

naikus
Author by

naikus

Systems Engineer for dynamic company that designs and leverages technology to accelerate, enhance, and revolutionize -- the way organizations source everything from complex, direct materials to everyday commodities.

Updated on September 17, 2022

Comments

  • naikus
    naikus over 1 year

    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

    • Justin Scott
      Justin Scott over 14 years
      If you don't need to keep the full logs around for any significant period of time, set the databases with the largest logs to 'Simple' backup mode and have your maintenance plan truncate them immediately after a full backup is done. This doesn't answer your question, of course, but may help keep the drive from getting full in the first place if your situation allows it.
    • naikus
      naikus over 14 years
      Thanks for the info. I did implement an extra backup job to help truncate the SQL log files and keep them from growing any larger. But I would like to put some sort of alert in place just in case. Thanks.
    • Admin
      Admin over 7 years
      We use Spiceworks to alert us of low disk space on all clients and servers.
  • naikus
    naikus over 14 years
    Right now I'm looking into a separate monitoring system (like IPMonitor), but I would like to put something in place on the servers to alert me in the meantime. Thanks.
  • Ved
    Ved over 12 years
    Does this only triggers for System drive (usually C drive) ? What if I have 2-3 driver and I want to setup alert on each of them.
  • paulH
    paulH over 11 years
    Event 2013 is logged for any partition that falls below the defined threshold - note that it is only logged once per partition, unless the disk space increases back above the threshold or the server is rebooted. support.microsoft.com/kb/112509
  • user1233802
    user1233802 over 7 years
    This script doesn't work. I get the error message that no position parameter is set.
  • John K. N.
    John K. N. over 7 years
    This is not really an answer to the original posting, but a correction to an answer. Additionally you are using a fixed IP address in the code instead of the value extracted from the server.txt file.
  • Pierre.Vriens
    Pierre.Vriens over 6 years
    I don't get it.
  • Baodad
    Baodad almost 6 years
    In newer versions of windows server, the "Send an e-mail" action is deprecated. Instead, you can use the "Start a Program" action, fill in powershell for the program and the following for arguments: -command &{send-mailmessage -from [email protected] -to [email protected] -subject 'Alert from Task Scheduler' -body 'This is an automated message from a task scheduled on the server. Testing powershell email.' -smtpserver x.x.x.x}