none
Reading logs from multiple log files and sending over emails RRS feed

  • Question

  • I am trying to read multiple line inside the logfiles from a single folder and sending over am email. I am able to get the logs from files but when i am trying to send this over email, the content of the email was not in readable form.
    $main = @()
    $total = 0
    $folder = "D:\HomeMigration\Logs"
    
    $files = Get-ChildItem -path $folder -Filter "*.txt"
    
    foreach ( $file in $files ) { $text = gc $folder\$file
                                  $main1 = $text[1..8] + $text[-10..-1]
                                  $main1 = $main1  | %{"$_<br/>"}
    
    
    
                                  $main1 = "<br>" +  $main1 + "<br/>"
                                  $main += $main1
                                                           
                                  
    
                                  
                                }
    
    Send-MailMessage -From ankit_sharma2@horizonblue.com -To ankit_sharma2@horizonblue.com -SmtpServer smtp.corpads.local -Subject "Log report " -body "$main" -BodyAsHtml
    
    
    Please help.
    Thursday, April 5, 2018 11:36 PM

Answers