Help with Sending Emails from Try/Catch Script

0
6
Asked By CleverCoder88 On

I'm working on a script where I want to email the results. The basic logic is working fine, but I'm having trouble with sending emails from the "Try" block. While I do receive an email when there's an error in the "Catch" block, nothing comes through for the successful execution of "Try". Below is the script snippet I've got so far, which retrieves DHCP filter logs for the last 24 hours and then tries to email the results. I'm looking for what might be going wrong. Thanks for any help!

3 Answers

Answered By PowerShellGuru On

You could also try adding some logging to see if the code is progressing to the email line in `Try`. Sometimes adding simple debug outputs before critical lines can reveal if the script is working as intended.

Answered By ScriptWhiz42 On

It seems like your `Get-WinEvent` might be encountering an error that's causing the `Catch` block to trigger instead of the email being sent from `Try`. Double-check if that command is completing successfully first. If there's no error message, it’s worth logging out the events to ensure they are being collected as expected.

Answered By DebugMaster99 On

You might want to verify that your `Try` block is actually closed properly. It looks like you might have missed closing it. It should encapsulate all the email functionality inside, so check that there are no missing braces. The absence of a proper scope might lead to unintended behaviors.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.