💽 PowerShell – Automated Disk Space Monitoring with HTML Dashboard & Email Alerts
- Avijit Dutta
- Aug 11
- 3 min read
Published on: August 09, 2025
Author: Avijit Dutta
Category: PowerShell | Microsoft | IT Infrastructure Administration

📌 Introduction
📜 PowerShell Script for Automated Disk Space Monitoring
Keeping an eye on disk space across many machines is a daily task for system administrators 🖥️. Manual checks are slow and error-prone, so here’s a simple, robust PowerShell solution that:
✅ Reads hostnames from C:\computer.txt
✅ Collects per-computer and per-drive disk metrics
✅ Produces a styled HTML report where any drive below 20% free is highlighted in 🔴 red
✅ Generates a beautiful HTML dashboard 📊
✅ Zips & Emails the report to designated recipients
PowerShell script for Automated Disk Space Monitoring is production-ready ⚡ but comes with sensible placeholders (SMTP server, credentials) so you can plug in your environment values.
Let’s dive in! 🚀
⚠️ Disclaimer: The script and instructions provided in this blog are for 🧑💻 educational purposes only. Please 🧪 test thoroughly in a controlled test environment before deploying in any 🏭 production system. The author is not responsible for ❌ damage, 📉 data loss, or ⏳ downtime caused by the misuse of this script.
🛠️ Prerequisites & Notes
📄 Save a file c:\computer.txt containing one hostname per line (FQDN or NetBIOS name).
👤 Run the script with an account that has permission to query remote Win32_LogicalDisk (WMI/CIM) on target machines.
💻 PowerShell 5.1+ or PowerShell 7 recommended.
🌐 Ensure network connectivity (RPC/WinRM or DCOM, depending on your environment). The script pings first 📡 — you can disable that if required.
📬 Configure SMTP settings (server, port, credentials) inside the script or pass them as parameters.
🧪 Test first in a lab/non-production environment.
🔍 What the Script Does — Step-by-step
1️⃣ Reads computers from "c:\computer.txt".
2️⃣ For each reachable computer, queries Win32_LogicalDisk (DriveType=3 - fixed local drives).
3️⃣ Builds an in-memory result set with per-drive Total GB, Free GB, and Free %.
4️⃣ Generates an HTML page with a clean style 🎨 - drives below 20% free are shown in red.
5️⃣ Writes C:\DiskReport.html.
6️⃣ Compresses it to C:\DiskReport.zip 📦.
7️⃣ Emails the ZIP to abc@gmail.com (📨 TO) and xyz@gmail.com (📩 CC).
8️⃣ Write status and warnings ⚠️ to the console for quick troubleshooting.
▶️ How to Run
1️⃣ Open C:\computer.txt and list hostnames (one per line).
2️⃣ Open the Disk_Report_Script.ps1 file (available in the right-side code panel) and:
Save it as C:\Scripts\Disk_Report_Script.ps1 🗂️
Or copy & paste into a PowerShell editor ✏️
3️⃣ Edit SMTP, From, To, and other parameters at the top of the script or run with parameters. Example:
.\Disk_Report_Script.ps1 -SmtpServer 'smtp.corp.example.com' -SmtpPort 587 -From 'reports@corp.example.com' -To 'abc@gmail.com' -Cc 'xyz@gmail.com' -UseSsl -Credential (Get-Credential)
4️⃣ Run as an account with remote query privileges 🔑.
📂 Sample Output Screenshot
Here’s a sample view of the HTML dashboard:
Computer Name | Total Disk Space (GB) | Drive | Total Space | Free Space | Free % |
Server01 | 500 | C: | 250 | 40 | 16% 🔴 |
Server01 | 500 | D: | 250 | 200 | 80% ✅ |
📥 Download the Script
The full script named "disk_report_script.ps1" is included in the zip file "disk_report_script.zip." You can download it, unzip it, and use it.
🛡️ Security Tips & Enhancements
🔐 Use secure mail transport (TLS) and service account credentials scoped to email-only.
🔄 Replace Send-MailMessage if your org uses Exchange Web Services, Graph API, or another secure transport.
⚡ For large environments, parallelise queries with Invoke-Command (-ThrottleLimit).
🗄️ Store credentials securely (Azure Key Vault / Windows Credential Manager).
📝 Add logging to a central location for auditability.
🎯 Conclusion
This script gives you a single, automated workflow to gather disk health 🖥️ across multiple computers, produce human-friendly reports, and deliver them to stakeholders — all with minimal setup 🚀.
It’s a great base for routine monitoring and can be extended with:
📊 Dashboards
📩 Email body summaries
🔗 Integration with monitoring platforms
☕ Found this helpful? Share it & show some love!
Tip me a coffee at 👉 paypal.me/duttaavijit #ThankYou #SupportCreators
Your small support helps fuel more free, volunteer-driven content like this. Thank you! 🙏
#PowerShell #SysAdmin #WindowsServer #ITAutomation #TechTips #ITMonitoring #SystemAdministration #WindowsManagement #ITTools #ITSupport #ServerMonitoring #AutomationScripts #InfrastructureMonitoring #DataCenter #ITOperations
Komentar