Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Drive space monitor with specific thresholds on all drives

Posted on 2013-02-05
4
Medium Priority
?
516 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 2000 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
This tutorial will show how to push an installation of Backup Exec to an additional server in both 2012 and 2014 versions of the software. Click on the Backup Exec button in the upper left corner. From here, select Installation and Licensing, then I…
This tutorial will walk an individual through locating and launching the BEUtility application and how to execute it on the appropriate database. Log onto the server running the Backup Exec database. In a larger environment, this would generally be …

704 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