Automate Disk Space Monitoring Using PowerShell and ServerEngine

Monitoring disk space on servers is a crucial task for any system administrator. Ensuring that your servers have enough free space can prevent service interruptions and improve performance. This PowerShell script automates the process of checking disk space across your network and can be integrated with our software, ServerEngine, to provide you with detailed reports and notifications.
With ServerEngine, you can manage your servers more efficiently, getting insights not just on disk space, but on many other vital server metrics as well. The integration of this script with ServerEngine will make it a powerful tool for proactive server management.
### PowerShell Script Overview
This script will scan specified servers and check the disk space of each drive. If any drive falls below a defined threshold, a notification will be sent. This proactive approach ensures that potential issues are addressed before they affect system performance.
Below is the PowerShell script for automated disk space monitoring. Make sure you have the necessary permissions to access the servers you want to monitor.

# Define the servers you want to check
$servers = "Server1", "Server2", "Server3"
# Define the threshold percentage for free space
$thresholdPercent = 20
# Loop through each server
foreach ($server in $servers) {
    # Get the logical drives
    $drives = Get-WmiObject -Class Win32_LogicalDisk -ComputerName $server
    # Loop through each drive
    foreach ($drive in $drives) {
        # Calculate the percentage of free space
        $freeSpacePercent = ($drive.FreeSpace/$drive.Size) * 100
        # Check if the free space is below the threshold
        if ($freeSpacePercent -lt $thresholdPercent) {
            # Send notification
            Write-Output "Warning: Drive $($drive.DeviceID) on $server is below $thresholdPercent% free space. Current free space is $freeSpacePercent%."
        } else {
            Write-Output "Drive $($drive.DeviceID) on $server is healthy with $freeSpacePercent% free space."
        }
    }
}