Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7068441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:19:27+00:00 2026-05-28T05:19:27+00:00

I have the following code snippet from my PowerShell script that… Loops through a

  • 0

I have the following code snippet from my PowerShell script that…

  • Loops through a list of servers
  • Does a Select-String -notmatch on the error log at each server
  • Flags the server if the error log is bad, and gives the OK if the error log if fine

What I’d like to also do is send an email report that enumerates each of the discovered bad error logs in a list, and also list all the servers whose error logs are OK. Something like this in the email body:

The following servers have bad error logs:

  • Server3
  • Server6
  • Server14

The following servers are OK:

  • Server1
  • Server2
  • Server5

Here is my code snippet:

$Servers = Get-Content $ServerLst
ForEach ($Server in $Servers)
{
   $ErrorLog = Get-ChildItem -Path \\$Server\$LOG_PATH -Include Error.log -Recurse | Select-String -notmatch $SEARCH_STR
   If ($ErrorLog)
   {
    Write-Host "Bad Error Log found at $Server!"
   }
   Else
   {
    Write-Host "Error log is OK."           
   }
}

I’m guessing I would need a Send-Mail function where I would pass in the server names with bad error logs, etc. However, I’m not quite sure how to approach this.

Any great ideas will be greatly appreciated. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:19:28+00:00Added an answer on May 28, 2026 at 5:19 am

    If you are using Powershell V1 use this function from the Powershell Cookbook to send mail. In Powershell V2 you can send mail using Send-MailMessage.

    $Servers = Get-Content $ServerLst
    $Bad = "The following servers have bad error logs:`n`n"
    $OK = "`nThe following servers are OK:`n`n"
    ForEach ($Server in $Servers)
    {
       $ErrorLog = Get-ChildItem -Path \\$Server\$LOG_PATH -Include Error.log -Recurse | Select-String -notmatch $SEARCH_STR
       If ($ErrorLog)
       {
        $Bad += "`t - $Server`n"
       }
       Else
       {
        $OK += "`t - $Server`n"           
       }
    }
    Send-MailMessage -Body "$Bad $OK" -Subject "Bad Logs" -SmtpServer $servername -To $to -From $from  
    

    Remark: The smtpserver parameter is called smtphost in the Powershell cookbook function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code snippet. SqlCommand cmd = new SqlCommand(SELECT FName,LName FROM EMPLOYEE_TABLE
I have the following snippet below from my script that's using a WebRequest to
From this site: http://www.toymaker.info/Games/html/vertex_shaders.html We have the following code snippet: // transformations provided by
I have the following snippet from my code: switch ($extention) { case gif: $src
I have following code snippet that i use to compile class at the run
I have used the following code snippet to logout the user from the session.
I have written the following code snippet to read data from the database :
I have the following code snippet: var matchingAuthors = from authors in DB.AuthorTable where
I have the following code snippet I'm trying to get the text from: <span
I have the following code snippet from a HTML file: <div id=rwImages_hidden style=display:none;> <img

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.