Solved

Drive space monitor with specific thresholds on all drives

Posted on 2013-02-05
4
505 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background Information Recently I have fixed file server permission issues for one of my client. The client has 1800 users and one Windows Server 2008 R2 domain joined file server with 12 TB of data, 250+ shared folders and the folder structure i…
A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…

734 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