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
Solved

Drive space monitor with specific thresholds on all drives

Posted on 2013-02-05
4
501 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

When we purchase storage, we typically are advertised storage of 500GB, 1TB, 2TB and so on. However, when you actually install it into your computer, your 500GB HDD will actually show up as 465GB. Why? It has to do with the way people and computers…
Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

808 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