Link to home
Start Free TrialLog in
Avatar of avwoolsey
avwoolseyFlag for United States of America

asked on

Drive space monitor with specific thresholds on all drives

Hello, all. This is my first foray into posting on this site, though I've been a consumer for a while now. I'm far from an expert at scripting, but I understand enough that, with the help of Google and Experts-Exchange, I can usually muddle through.

My resent task is of a rather specific nature. The short version is this: I need to monitor and alert on each drive on every server in my environment when they dip below a predefined threshold. I've found this type of script here, however, the difference I need (and what I'm envisioning) is pulling the list from a text file like so:

server1 c 5
server1 e 10
server1 f 4
server2 c 5

In the above example, the script would pull the server names from a text file, and it would then know the drive letter it needs to monitor as well as the %-specific threshold for that given drive.

The scripts I've found so far all have a set threshold for all drives and all servers. This seems like a very odd way of doing it, given the huge variance in drive capacities on all of the possible servers in a given environment. That is to say, 5% of a 50 GB drive is considerably different from 5% of a 3 TB drive.

If an example of this type of script exists, a link would be wonderful. I've Googled it every way I can think of, to no avail. Thank you in advance.
Avatar of Manpreet SIngh Khatra
Manpreet SIngh Khatra
Flag of India image

ASKER CERTIFIED SOLUTION
Avatar of SubSun
SubSun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
And if you need a HTML formatted alert, then try this..
$Servers = Import-Csv "C:\ServerList.csv"

$a = "<style>"
$a = $a + "BODY{background-color:peachpuff;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}"
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:palegoldenrod}"
$a = $a + "</style>"

Foreach ($server in $Servers){
$Disk = Get-WmiObject win32_volume -ComputerName $server.ServerName | 
 where {$_.DriveType -like "3" -and $_.caption -eq "$($Server.Drive):\"} | 
  Select @{L="Server";E={$server.ServerName}},caption,`
	  @{L="TotalSpace";E={$([math]::Round(($_.Capacity/1073741824),0))}},`
	   @{L="freeSpace";E={$([Math]::Round(($_.FreeSpace/1073741824),0))}}

$freePercent = [Math]::Round(($($Disk.freeSpace/$Disk.TotalSpace)*100),0)
if ($freePercent -le $Server.Threshold)
 {
	$Body = $Disk | Select Server,caption,TotalSpace,freeSpace,@{L="freePercent";E={$freePercent}} |
	ConvertTo-Html -head $a -body "<H2>Disk Information</H2>" | Out-String

	Send-MailMessage `
		-From subsun@domain.com `
		-To subsun@domain.com `
		-Subject "$($Disk.Server): Disk space on $($Disk.caption)(%) is low - $((Get-Date).ToString('MM/dd/yyyy h:mm:ss tt'))" `
		-BodyAsHtml $Body `
		-SmtpServer smtp.domain.com
 }
}

Open in new window

Avatar of avwoolsey

ASKER

This is exactly what I was looking for in a solution. Thank you very, very much.