Solved

Drive space monitor with specific thresholds on all drives

Posted on 2013-02-05
4
494 Views
Last Modified: 2013-02-06
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.
0
Comment
Question by:avwoolsey
  • 2
4 Comments
 
LVL 52

Expert Comment

by:Manpreet SIngh Khatra
ID: 38856346
0
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 38858635
Try this..
$Servers = Import-Csv "C:\ServerList.csv"

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 | 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.mail.com
 }
}

Open in new window

CSV Format
ServerName,Drive,Threshold
HostA,c,5
HostB,e,10

Open in new window

You can schedule the  script to run at regular intervals to monitor the disk space..
0
 
LVL 40

Expert Comment

by:Subsun
ID: 38858646
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

1
 

Author Closing Comment

by:avwoolsey
ID: 38860878
This is exactly what I was looking for in a solution. Thank you very, very much.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
This article will help you understand what HashTables are and how to use them in PowerShell.
This tutorial will give a an overview on how to deploy remote agents in Backup Exec 2012 to new servers. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as connecting to a remote Back…
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now