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 7072343
In Process

The Archive Base Latest Questions

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

I have the following code (thanks to input from ‘jon Z’ and ‘manojlds’) that

  • 0

I have the following code (thanks to input from ‘jon Z’ and ‘manojlds’) that processes server lists, checks the error logs for each server against a search string, and then sends an email report listing the servers with bad error logs and good error logs.

What I would like to do now is do a count of the number of servers with bad error logs and good error logs and put that info in the email report as well.

I would have something like this in each heading of my email report:

The following n servers have bad error logs:

The following n servers are OK:

I’ve been trying to accomplish this by using the Count method, but have so far been unsuccessful. Is the Count method the correct approach? Is so, how (where would I apply it in my code)? If not, then what is the best approach?

Code:

$BadServerLogs = "<font style=`"font-family:verdana;font-size:9pt`"><p><b>The following servers have bad error logs:</b></p>"
$GoodServerLogs = "<font style=`"font-family:verdana;font-size:9pt`"><p><b>The following servers are OK:</b></p>"

# Use hash table to associate server list to search string array
$Groups = @{
$SERVER_LST_1=$SEARCH_STR_ARRAY_1;
$SERVER_LST_2=$SEARCH_STR_ARRAY_2;
$SERVER_LST_3=$SEARCH_STR_ARRAY_3;
$SERVER_LST_4=$SEARCH_STR_ARRAY_4;
}
$StartupErrors = @{}
$Groups.keys | %{
$key = $_
gc $key | %{
    # Check StartupError.log files for errors
    $StartupErrors[$_] = Get-ChildItem -Path \\$_\$LOG_PATH -Include StartupError.log -Recurse | Select-String -notmatch $Groups["$key"]
    If ($StartupErrors[$_])
    {
        $Subject = "StartupError Logs Report: BAD ERROR LOGS!"
        $BadServerLogs += "<li><a href=`"\\$_\$LOG_PATH\StartupError.log`">$_</a></li>"
    }
    Else 
    { 
        $Subject = "StartupError Logs Report: All Logs are Fine"
        $GoodServerLogs += "<li>$_</li>" 
    }
}   
}
# Send email listing servers with bad/good StartupError log files
Send-MailMessage -Body "$BadServerLogs $GoodServerLogs" -BodyAsHtml -Subject $Subject -SmtpServer $SmtpServer -To $MailTo -From $MailFrom

Thanks in advance! -Keith

  • 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:47:51+00:00Added an answer on May 28, 2026 at 5:47 am

    You can just create two variables:

    $goodCount = 0
    $badCount = 0
    

    Then in the loop increment each depending on the case:

    If ($StartupErrors[$_])
    {
        $Subject = "StartupError Logs Report: BAD ERROR LOGS!"
        $BadServerLogs += "<li><a href=`"\\$_\$LOG_PATH\StartupError.log`">$_</a></li>"
        $badCount += 1
    }
    Else 
    { 
        $Subject = "StartupError Logs Report: All Logs are Fine"
        $GoodServerLogs += "<li>$_</li>"
        $goodCount += 1
    }
    

    Then create some HTML and send it:

    $html = "<h1>The following $badCount servers have bad error logs:</h1>" + $BadServerLogs
    $html += "<h1>The following $goodCount servers are OK:</h1>" + $GoodServerLogs
    
    Send-MailMessage -Body $html -BodyAsHtml -Subject $Subject -SmtpServer $SmtpServer -To $MailTo -From $MailFrom
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hallo, I have following jquery code for calling ASP.NET MVC controller method that is
I have the following asm code (x86). .input: mov ah, 00h ; get key
I have the following code to read in from a file #include <queue> #include
I have the following HTML code: <input type=checkbox value=1 /> <input type=checkbox value=2 />
All, I have the following code: $qry = Select * from vendor_options order by
I currently have the following code to get a specific value i need from
i have the following code for search from database show return result to the
Say I have a textbox in HTML using the following code: <input type=text name=text
I have following code: <div class='parent'> <div class='left-child'></div> <div class=right-child></div> </div> What I want
I have following code snippet and i am trying to evaluate the time take

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.