Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <######################################################################
- #
- # Author : Douglas Baker :Tom Seiver
- # Date : 9/27/2012 : Revision :11/9/2016
- # Version : 1.1
- # Desctiption : This script produces a html output that shows server drive inventory with colorcoding though css : Revised to include an email if "alert" is triggered
- # Update note : 1.0 let it begin!
- #
- ######################################################################>
- $outfile = "W:\wwwroot\helpdesk\drives.htm"
- $serverlist = Get-Content "c:\Scripts\server-list.txt"
- $time = get-date
- # Credentials for email
- $Username = "MyUserName";
- $Password= "MyPassword";
- # This is a function Actually sends an email.
- # Edit this part of the code to fit youre requirements.
- function Send-ToEmail([string]$email, [string]$attachmentpath){
- $message = new-object Net.Mail.MailMessage;
- $message.From = "YourName@gmail.com";
- $message.To.Add($email);
- $message.Subject = "subject text here...";
- $message.Body = "body text here...";
- $attachment = New-Object Net.Mail.Attachment($attachmentpath);
- $message.Attachments.Add($attachment);
- # you will need to edit this so that it may work with your companys secure mail transfer protocol (smtp).
- # make sure you the right smtp and port number or it wont work
- $smtp = new-object Net.Mail.SmtpClient("smtp.gmail.com", "587");
- $smtp.EnableSSL = $true;
- $smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);
- $smtp.send($message);
- write-host "Mail Sent" ;
- $attachment.Dispose();
- }
- $HTML = " --><!DOCTYPE html>
- <html>
- <head>
- <meta charset='UTF-8'>
- <link rel='apple-touch-icon' href='/favicon.jpg'/>
- <link rel='apple-touch-icon-precomposed' sizes='114x114' href='favicon-114.jpg'>
- <title>Drive Inventory</title>
- <LINK REL=StyleSheet HREF='default.css' TYPE='text/css'>
- </head>
- <body>
- last updated $time
- <table> <thead>
- <TR>
- <TH>Server</TH>
- <TH>Drive</TH>
- <TH>Description</TH>
- <TH>Size(GB)</TH>
- <TH>Free space(GB)</TH>
- </TR>
- </thead>
- <tbody>"
- Foreach($ServerName in $ServerList){
- $driveinventory = Get-WmiObject -class win32_LogicalDisk -filter "DriveType=3" -computername $servername
- foreach($drive in $driveinventory)
- {
- # This is the conditional where you want the email to be sent.
- if ($drive.Freespace -lt ($Drive.Size*.10 )) {
- $status = 'alert'
- # This triggerse the function we declared at the bottom and sends an email
- Send-ToEmail -email "reciever@gmail.com" -attachmentpath $path;
- }
- elseif ($drive.Freespace -lt ($Drive.Size*.25 ),$EmailServer = "kona-vm1.surterreproperties.com"
- $EmailFrom = "Help Desk <helpdesk@Surterreproperties.com>"
- $emailto = @("Doug <dbaker@surterreproperties.com>") {$status ='caution'}
- ELSE {$status = 'normal'}
- $html += "<tr class='$status'>
- <td>$servername</td>
- <td>$($drive.deviceid)</td>
- <td>$($drive.Volumename)</td>
- <td> $($drive.size/1gb -as[int])</td>
- <td> $($drive.Freespace/1gb -as[int])</td>
- </tr> "
- #write-host $servername $drive.deviceid $drive.Volumename ($drive.size/1gb -as[int]) ($drive.Freespace/1gb -as[int])
- }
- $html += " "
- }
- $HTML += "</tbody></table></div></BODY></HTML>"
- $HTML | Out-File $outfile
Add Comment
Please, Sign In to add comment