Guest User

Untitled

a guest
Nov 11th, 2016
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <######################################################################
  2. #                                                                  
  3. # Author       : Douglas Baker    :Tom Seiver                          
  4. # Date         : 9/27/2012        : Revision :11/9/2016                            
  5. # Version      : 1.1                                               
  6. # 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
  7. # Update note  : 1.0 let it begin!
  8. #                                                                  
  9. ######################################################################>
  10. $outfile = "W:\wwwroot\helpdesk\drives.htm"
  11. $serverlist = Get-Content "c:\Scripts\server-list.txt"
  12. $time = get-date
  13.  
  14. # Credentials for email
  15. $Username = "MyUserName";
  16. $Password= "MyPassword";
  17.  
  18. # This is a function Actually sends an email.
  19. # Edit this part of the code to fit youre requirements.
  20. function Send-ToEmail([string]$email, [string]$attachmentpath){
  21.  
  22.     $message = new-object Net.Mail.MailMessage;
  23.     $message.From = "YourName@gmail.com";
  24.     $message.To.Add($email);
  25.     $message.Subject = "subject text here...";
  26.     $message.Body = "body text here...";
  27.     $attachment = New-Object Net.Mail.Attachment($attachmentpath);
  28.     $message.Attachments.Add($attachment);
  29.  
  30.     # you will need to edit this so that it may work with your companys secure mail transfer protocol (smtp).
  31.     # make sure you the right smtp and port number or it wont work
  32.     $smtp = new-object Net.Mail.SmtpClient("smtp.gmail.com", "587");
  33.     $smtp.EnableSSL = $true;
  34.     $smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);
  35.     $smtp.send($message);
  36.     write-host "Mail Sent" ;
  37.     $attachment.Dispose();
  38.  }
  39.  
  40. $HTML = " --><!DOCTYPE html>
  41. <html>
  42. <head>
  43.     <meta charset='UTF-8'>
  44. <link rel='apple-touch-icon' href='/favicon.jpg'/>
  45. <link rel='apple-touch-icon-precomposed' sizes='114x114' href='favicon-114.jpg'>
  46.    
  47.     <title>Drive Inventory</title>
  48.    <LINK REL=StyleSheet HREF='default.css' TYPE='text/css'>
  49. </head>
  50. <body>
  51. last updated $time
  52.    <table> <thead>
  53.         <TR>
  54.            <TH>Server</TH>
  55.             <TH>Drive</TH>
  56.             <TH>Description</TH>
  57.             <TH>Size(GB)</TH>
  58.             <TH>Free space(GB)</TH>
  59.         </TR>
  60.        </thead>
  61.        <tbody>"
  62. Foreach($ServerName in $ServerList){
  63.     $driveinventory = Get-WmiObject -class win32_LogicalDisk -filter "DriveType=3" -computername $servername
  64.    
  65.     foreach($drive in $driveinventory)
  66.         {
  67.             # This is the conditional where you want the email to be sent.
  68.             if ($drive.Freespace -lt ($Drive.Size*.10 )) {
  69.                 $status = 'alert'
  70.  
  71.                 # This triggerse the function we declared at the bottom and sends an email
  72.                 Send-ToEmail  -email "reciever@gmail.com" -attachmentpath $path;
  73.             }
  74.             elseif ($drive.Freespace -lt ($Drive.Size*.25 ),$EmailServer = "kona-vm1.surterreproperties.com"
  75. $EmailFrom = "Help Desk <helpdesk@Surterreproperties.com>"
  76. $emailto = @("Doug <dbaker@surterreproperties.com>") {$status ='caution'}
  77.             ELSE {$status = 'normal'}
  78.            
  79.             $html += "<tr class='$status'>
  80.                        <td>$servername</td>
  81.                        <td>$($drive.deviceid)</td>
  82.                        <td>$($drive.Volumename)</td>
  83.                        <td> $($drive.size/1gb -as[int])</td>
  84.                        <td>  $($drive.Freespace/1gb -as[int])</td>
  85.                    </tr> "
  86.         #write-host $servername $drive.deviceid $drive.Volumename ($drive.size/1gb -as[int]) ($drive.Freespace/1gb -as[int])
  87.         }
  88.     $html += " "
  89. }
  90. $HTML += "</tbody></table></div></BODY></HTML>"
  91. $HTML | Out-File $outfile
Add Comment
Please, Sign In to add comment