Here’s everything you need to know about this powerful PowerShell disk space monitoring script.
What This PowerShell Script Does
This comprehensive PowerShell script is designed to monitor disk space across multiple Windows servers and generate professional reports. Here’s exactly what it accomplishes:
Core Functionality:
- Multi-Server Monitoring: Reads a list of servers from a text file and checks disk space on each one
- WMI Integration: Uses Win32_LogicalDisk WMI class to gather accurate disk information
- Connectivity Testing: Tests server connectivity before attempting to collect data
- Error Handling: Gracefully handles offline servers and access issues
- Dual Output Formats: Generates both CSV and HTML reports simultaneously
Data Collection Process:
- Reads server names from
C:\Temp\Server.txt
- Tests network connectivity to each server
- Queries WMI for disk information (DriveType=3 for fixed disks)
- Calculates disk usage statistics in GB
- Determines free space percentages
- Creates timestamped reports
Server List Format:
The script expects a simple text file with one server name per line:
SERVER01
SERVER02
DC-01
WEB-SERVER-01
# This is a comment line (ignored)
Report Outputs
CSV Report Features:
- File Location:
C:\Temp\Report\DiskSpaceReport_YYYYMMDD_HHMMSS.csv
- Format: One row per drive per server
- Columns: Server, Drive, Total Capacity(GB), Used Capacity(GB), Free Space(GB), Freespace %
- Excel Compatible: Can be opened directly in Excel for analysis
- UTF-8 Encoding: Supports international characters
HTML Report Features:
- Interactive Interface: Click server names to expand/collapse drive details
- Visual Alerts: Color-coded warnings for drives with <20% free space
- Professional Styling: Clean, modern design with responsive layout
- Summary Section: Shows total drives, successful/error servers, generation time
- Expand/Collapse Controls: Button to expand/collapse all servers at once
- Low Disk Space Warnings: Dedicated alert section for critical drives
HTML Report Sections:
- Header: Report title and generation timestamp
- Summary: Statistics about processed servers and drives
- Controls: Expand/collapse all servers button
- Warning Section: Lists drives with <20% free space (if any)
- Main Table: Interactive server/drive data with expandable rows
- Footer: Instructions and generation details
Technical Specifications
Parameters:
$ServerListFile
: Path to server list (default:C:\Temp\Server.txt
)$OutputCSV
: CSV output path with timestamp$OutputHTML
: HTML output path with timestamp
Functions:
Get-SafeDiskInfo
: Safely retrieves disk information with error handlingConvert-BytesToGB
: Converts bytes to GB with 2 decimal precision
Data Processing:
- Drive Filtering: Only processes fixed disk drives (DriveType=3)
- Calculations: Total, Used, Free space in GB; Free space percentage
- Error Records: Creates error entries for inaccessible servers
- Grouping: HTML report groups drives by server for better organization
Sample Output Data
CSV Format:
Server,Drive,Total Capacity(GB),Used Capacity(GB),Free Space(GB),Freespace %
SERVER01,C,499.87,245.32,254.55,50.93
SERVER01,D,931.51,125.67,805.84,86.51
SERVER02,C,279.45,198.23,81.22,29.07
SERVER02,ERROR,N/A,N/A,N/A,N/A
Console Output:
- Progress indicators for each server
- Success/error status with color coding
- Summary statistics
- Sample results preview
- Low disk space warnings (if any)
Alert System
Low Disk Space Detection:
- Threshold: Automatically flags drives with <20% free space
- Console Warnings: Red text warnings in PowerShell output
- HTML Highlighting: Special background color for low-space drives
- Dedicated Section: Separate warning area in HTML report
Error Handling:
- Connection Failures: Marked as “ERROR” in reports
- Access Denied: Logged with specific error messages
- Missing Data: Gracefully handled with “N/A” values
- File System Issues: Comprehensive error logging
File Structure Required
C:\Temp\
├── Server.txt (your server list)
└── Report\ (auto-created)
├── DiskSpaceReport_20241215_143022.csv
└── DiskSpaceReport_20241215_143022.html
Setup Requirements
- PowerShell Version: 5.1 or higher
- Permissions: Administrator rights recommended
- Network Access: WMI access to target servers
- Firewall: Ports 135 and dynamic RPC ports open
- Authentication: Current user must have admin rights on target servers
Download Script
Ready to implement professional disk space monitoring for your Windows environment?
Use Cases
- Daily Health Checks: Monitor server storage daily
- Capacity Planning: Track storage growth trends
- Maintenance Windows: Pre/post maintenance comparisons
- Compliance Reporting: Generate storage utilization reports
- Proactive Monitoring: Prevent storage-related outages
Video Demonstration
Watch the complete walkthrough on my YouTube channel to see this script in action and learn advanced configuration tips!
A big thank you for exploring TechsBucket! Your visit means a great deal to us, and we appreciate the time you spend on our platform. If you have any feedback or suggestions, we’d love to hear them.