03 9695 5408 info@melbournecityit.com.au
Melbourne IT services, IT support | Melbourne City ITMelbourne IT services, IT support | Melbourne City IT
  • Home
  • Services
    • – Website development
    • – SEO Service
    • – IT consulting
    • – VoIP
    • – IT Support
    • – Cyber Security
    • – Linux
    • – Cloud Solution
    • – Website Hosting
  • Contact
  • Blogs
  • Member
  • Home
  • Services
    • – Website development
    • – SEO Service
    • – IT consulting
    • – VoIP
    • – IT Support
    • – Cyber Security
    • – Linux
    • – Cloud Solution
    • – Website Hosting
  • Contact
  • Blogs
  • Member

Windows Support

  • Home
  • Blog
  • Windows Support
  • Monitoring your Hard disk space with Powershell

Monitoring your Hard disk space with Powershell

  • Categories Windows Support
  • Date August 17, 2021
IT services Melbourne

Disk space is one of the BIG 4(RAM, Disk, CPU, Network) we should monitor on daily basis, low usage of which will disturb your business and may cause disaster!

On a windows server, a powershell and scheduled task can get this job done.

 

Step 1 Get a email ready

To avoid the fall in the junk mailbox, you'd better use a real email account to send this. I usually create a Gmail account with APP password for it.

 

Step 2 Write a Powershell script

I will set 50G as a threshhold at which the script will send a warning email, or else just send a Info email, so you know your script still works.
Drives to check: set to $null to check all local (non-network) drives, or uncomment below line and comment the line below it.

# $drives = @("C","D");
$drives = $null;

# The minimum disk size to check for raising the warning
$minSize = 50GB;

# SMTP configuration: username, password & so on
$email_username = "your_username@gmail.com";
$email_password = "your password";
$email_smtp_host = "smtp.gmail.com";
$email_smtp_port = 587;
$email_smtp_SSL = 1;
$email_from_address = "youremail@gmail.com";
$email_to_addressArray = @("user1@domain.com", "user2@domain.com");

if ($drives -eq $null -Or $drives -lt 1) {
$localVolumes = Get-WMIObject win32_volume;
$drives = @();
foreach ($vol in $localVolumes) {
if ($vol.DriveType -eq 3 -And $vol.DriveLetter -ne $null ) {
$drives += $vol.DriveLetter[0];
}
}
}
foreach ($d in $drives) {
Write-Host ("`r`n");
Write-Host ("Checking drive " + $d + " ...");
$disk = Get-PSDrive $d;
if ($disk.Free / 1MB -lt $minSize) {
Write-Host ("Drive " + $d + " has less than " + $([math]::round(($minSize / 1GB),2)) `
+ " GBs free (" + $([math]::round(($disk.Free / 1GB),2)) + "): sending e-mail...");

$message = new-object Net.Mail.MailMessage;
$message.From = $email_from_address;
foreach ($to in $email_to_addressArray) {
$message.To.Add($to);
}
$message.Subject = ("[RunningLow] WARNING: " + $env:computername + " drive " + $d);
$message.Subject += (" has less than " + $([math]::round(($minSize / 1GB),2)) + " GBs free ");
$message.Subject += ("(" + $([math]::round(($disk.Free / 1GB),2)) + ")");
$message.Body = "Hello there, `r`n`r`n";
$message.Body += "this is an automatic e-mail message ";
$message.Body += "sent by RunningLow Powershell script ";
$message.Body += ("to inform you that " + $env:computername + " drive " + $d + " ");
$message.Body += "is running low on free space. `r`n`r`n";
$message.Body += "--------------------------------------------------------------";
$message.Body += "`r`n";
$message.Body += ("Machine HostName: " + $env:computername + " `r`n");
$message.Body += "Machine IP Address(es): ";
$ipAddresses = Get-NetIPAddress -AddressFamily IPv4;
foreach ($ip in $ipAddresses) {
if ($ip.IPAddress -like "127.0.0.1") {
continue;
}
$message.Body += ($ip.IPAddress + " ");
}
$message.Body += "`r`n";
$message.Body += ("Used space on drive " + $d + ": " + $([math]::round(($disk.Used / 1GB),2)) + " GBs. `r`n");
$message.Body += ("Free space on drive " + $d + ": " + $([math]::round(($disk.Free / 1GB),2)) + " GBs. `r`n");
$message.Body += "--------------------------------------------------------------";
$message.Body += "`r`n`r`n";
$message.Body += "This warning will fire when the free space is lower ";
$message.Body += ("than " + $([math]::round(($minSize / 1GB),2)) + " GBs `r`n`r`n");
$message.Body += "`r`n";
$message.Body += " ";

$smtp = new-object Net.Mail.SmtpClient($email_smtp_host, $email_smtp_port);
$smtp.EnableSSL = $email_smtp_SSL;
$smtp.Credentials = New-Object System.Net.NetworkCredential($email_username, $email_password);
$smtp.send($message);
$message.Dispose();
write-host "... E-Mail sent!" ;
}
else {
Write-Host ("Drive " + $d + " has more than " + $([math]::round(($minSize / 1GB),2)) + " GBs free: nothing to do.");
}
}
Save this script to a place, such as c:\scripts\disk_check.ps1

Step3, setup the scheduled task

Now, we will setup a task scheduler to  let it run at 6am every day.

Run the Task Scheduler, right click Task Scheduler Library.

  • Give it a name, click next,
  • Leave Daily as default, click next,
  • Daily: change the starting date, and occurring time, click Next,
  • Action: choose "Start a program", click next,
  • In the Program/script box, type:
    C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
    Add argument (optional):
    -Command "& c:\scripts\disk_check.ps1
    Then, click Next
  • Now click Finish.

Now find the task you just created, right click and select properties, choose "Run whether user is logged on or not", "Run with highest privileges".

 

Now you should see your email warning/notification every day!

 

  • Share:
Frank Fu

Previous post

Block IP addresses by Country in 3CX
August 17, 2021

Next post

What Challenges Does the Development of Strong AI Face?
August 17, 2021

You may also like

  • hide_update
    Windows Printing issue
    16 December, 2021
  • Fix-Windows-10-Remote-Desktop-Connects-frozen-Screen-Error-MelbourneCityIT
    Fix Remote desktop Frozen issue
    7 July, 2020

Services

  • Consulting
  • IT support
  • Telephony (VoIP)
  • Cyber Security

Recent Posts

  • Melbourne cPanel and VPS Hosting That Powers Local business
  • Windows Printing issue
  • WordPress pages except homepage showing blank
  • What Challenges Does the Development of Strong AI Face?
  • Monitoring your Hard disk space with Powershell

SERVICES

  • Website Development
  • Cloud Solution
  • Cyber Security
  • Consulting
  • VoIP Service
  • IT Support
  • Linux Service

CONTACT US

  • info@melbournecityit.com.au
  • 03 9695 5408

Blog

Melbourne cPanel and VPS Hosting That Powers Local business
Charlie F
March 11, 2026

Melbourne cPanel and VPS Hosting That Powers Local business

Windows Printing issue
Frank Fu
December 16, 2021

Windows Printing issue

WordPress pages except homepage showing blank
Frank Fu
August 30, 2021

WordPress pages except homepage showing blank

Featured Clients

  • Essendon Eye Clinic
  • North West Eye Specialist
  • Essendon Retina
  • McKinnon Eye Clinic
  • CATARACT & EYE SURGERY MELBOURNE
  • KMCable
  • iPhone Repair Melbourne
  • Smart Home Solution Melbourne
  • How Interior Design
  • Cornerstone Assets

© Melbourne City IT 2026