Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2562

PowerShell Email Alert for Failed Task

$
0
0

Hello All,

I need some help with PowerShell. I have 0 experience with it so I am coming here for advice.

I have a task scheduled on a Windows 2008 R2 server. It is a batch file that uses the net start and net stop commands to restart a service every morning. Unfortunately the service/task has started to fail for the last few weeks. 

During the failed days, the task comes back with a return code of 2 while on successful days it comes back with a return code of 0. I tried attaching a task with the scheduled even in the task scheduler but it only looks at the "Action Code" for the even and its the same for both. 

So setting up the email alert would not work as it would only look at action code and I only want to send alerts when the tasks fails. I read somewhere that you can "wrap" power shell script around the batch file and set up alert that way but the website was not clear enough. And with my limited knowledge on PowerShell, I couldn't trouble shoot the issue based on what they were saying. 

I was wondering if anyone would be kind enough to guide me through setting up the task or show me the way in terms of how it should be done.

Regards


Viewing all articles
Browse latest Browse all 2562

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>