Send a HTML email report in a formatted table - Send-HtmlEmail

This will take any Object from the PowerShell interface, convert the object (table) into HTML and then send it by email.

 
 
 
 
 
4.8 Star
(5)
7,568 times
Add to favorites
6/5/2013
E-mail Twitter del.icio.us Digg Facebook
  • Missing tags in the css part?
    3 Posts | Last post June 05, 2013
    • Hello Ben
      
      First of all, thanks very much for posting this PS function and I have started using it in my work. But I do find something wrong (at least on my Win7 with Powershell 3.0 platform). I have to add <style> and </style> tags in the @CSS definition part to make the email displayed properly. Would you please care to comment?
      
      
      if (!$CSS) 
      { 
      # Please use the download link to get the CSS it may not display correctly here.     
      $CSS = @" 
      
      <style>         
                  table { 
                  font-family: Verdana; 
                  border-style: dashed; 
                  border-width: 1px; 
                  border-color: #FF6600; 
                  padding: 5px; 
                  background-color: #FFFFCC; 
                  table-layout: auto; 
                  text-align: center; 
                  font-size: 8pt; 
                  } 
       
                  table th { 
                  border-bottom-style: solid; 
                  border-bottom-width: 1px; 
                  font: bold 
                  } 
                  table td { 
                  border-top-style: solid; 
                  border-top-width: 1px; 
                  } 
                  .style1 { 
                  font-family: Courier New, Courier, monospace; 
                  font-weight:bold; 
                  font-size:small; 
                  } 
      </style>             
      "@ 
      }#End if 
      
      
      cheers
      Nick
      
    • hi Nick,
      
      Yeah sorry about that and thank you.
      
      the code does now show up, I will add it back in with comments, hopefully that should fix it up.
    • Actually the one with the download link should work fine you would be best using that one.
  • How to use this script to invoke the result of another script?
    4 Posts | Last post November 13, 2012
    • Hi Ben, 
      I have a PS script which collects information from Exchange and puts the output in root of C as an .html file. I want this .html file to be appended in the body of the email (not as an attachment) and then emailed to Admins.
      I tried to do this with this script but in vain..
      I am not an expert of scripting and need your help please
    • If you already have a html file you can just use the native PowerShell cmdlet to send an email.
      $body = Get-Content -path c:\yourfile.html
      send-mailmessage -body $body -bodyashtml . . . .
    • Ben, this couldn't have been much easier with PS. 
      You have made my reports to look so neat and perfect.
      
      Thanks a ton
    • Hi Sai,
      
      Glad that you found it useful.
      
      Please feel free to leave a rating if you think others may find it useful as well.
      
      Ben.
  • Integration with VBScript/PS --
    2 Posts | Last post April 02, 2011
    • Is there any way to utilize this to pull all data from a specified directory?  I am slightly new to the PowerShell scene, and I am really having fun with a few other things I've found on here.  
    • My example just happened to be with a Get-ChildItem which is the PowerShell version of the Dir command.
      
      If you use my example and expand on it then that should solve your problem.
      
      - You can see I specify the Direcory to search
      - I use the recurse switch to get subdirectories as well
      - I specify the default headings to select for the report
      - I sort the table by the size of the files (from largest to smallest)
      
      $Directory = "C:\PS"
      $FileInfo = Get-ChildItem -Path $Directory -Recurse | Select-Object Name, Length, LastWriteTime, Mode | sort Length -Descending
      Send-HTMLEmail -InputObject $FileInfo -To User@domain.org -Subject "Directory Information"
      
      Please give that a try and if you need any more modifications or suggestions please feel free to let me know.