I have a Windows Server 2012 R2 Datacenter virtual machine running in Azure.

Recently, one of my disks ran out of space.

How can i setup a notification system to alert me when one of the disk drives runs low on disk space?

The only thing that comes to mind is to write a powershell script, but i'm wondering if there is a better way to do this, e.g via something on the Server Manager/Dashboard of Windows Server? I can't see any way to do this via Azure either.



This right here will do ya:

Event ID 2013 (Disk Is At Or Near Capacity) not getting logged

To summarize, make sure you're logging disk space alerts in your event log:


(You must add both of those, not just one or the other.)

Then you must attach a task to the event. And here is some XML that you can import into task scheduler that will attach said task to said event:

<?xml version="1.0" encoding="UTF-8"?>
<Task xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task" version="1.3">
      <Description>Send an emailed warning when a low disk space event is recorded.</Description>
         <Subscription>&amp;lt;QueryList&amp;gt;&amp;lt;Query Id="0" Path="System"&amp;gt;&amp;lt;Select Path="System"&amp;gt;*[System[Provider[@Name='srv'] and EventID=2013]]&amp;lt;/Select&amp;gt;&amp;lt;/Query&amp;gt;&amp;lt;/QueryList&amp;gt;</Subscription>
      <Principal id="Author">
   <Actions Context="Author">
         <Subject>Low disk space warning on server: [ServerName]</Subject>
         <Body>Disk space is running low on server: [ServerName] - please investigate.</Body>
         <HeaderFields />
         <Attachments />

You need to edit the SMTP server and other variables to suit your needs. This will fire off an email to you whenever that event (low disk space) occurs on your server.

It's worth noting that Server 2008, 2012, etc., should automatically default to generating this alert at 10% so there's probably no need to modify the registry unless you want something custom instead of 10%.

Alternatively, you can do it with Powershell.

$Threshold = 10 #Percent

Foreach($Disk In Get-CimInstance Win32_LogicalDisk | Where DriveType -EQ 3)
    $PercentFree = [Math]::Round(($Disk.FreeSpace / $Disk.Size) * 100, 1)
    If ($PercentFree -LT $Threshold)
        Send-MailMessage -From $From -To $To -Subject "Low Disk Space on $Servername" -Body "Low Disk Space on $Servername" -SmtpServer $SMTPServer

Schedule that and run it at an interval. (I just mocked that up off the top of my head but you get the idea.)

| improve this answer | |

You could do this from outside the VM by invoking Powershell from outside the VM to check the disk space of the VM's HDD. This is a good article on how to use Remote Powershell http://michaelwasham.com/windows-azure-powershell-reference-guide/introduction-remote-powershell-with-windows-azure/

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.