Powershell Script for an alert
I trying to run a powershell script as a "Run Program" choice in a alert. When I enter: powershell -command "C:\serveralert.ps1" from the "Run" option the script is successful. But when I place the same in the "Run Program" selection in a counter alert I get "The specified program or command file does not exist" What do I need to do to get a powershell script to work for an alert? (I also have this question posted to the powershell forum)
May 2nd, 2010 5:44am

After some research I have determined the problem but I do not know what to do about it. In performance logs and alerts command line arguments are added to any program that is in "Run Program." If I am running a VB script this will introduce errors and stop exection. If you could deselect all the command line options this might work but if at least one option is not selected the script will not run at all. I tried just selecting a text option and leaving it blank but that still screwed up the exection of the script. Is there anyway to solve this?
Free Windows Admin Tool Kit Click here and download it now
May 3rd, 2010 4:43am

Try putting in the full path to Powershell.exe, e.g. %windir%\system32\windowspowershell\v1.0\powershell.exe "C:\serveralert.ps1" Tony
May 3rd, 2010 5:46am

The solution seems to be to wrap the powershell script in a batch file and have the "Run Program" option call the batch file. It works better if the batch file and script in the same folder.
Free Windows Admin Tool Kit Click here and download it now
May 4th, 2010 4:11am

You shouldn't need to do that. In the task properties, choose Start a Program. In the Program/script section, type the following (or just browse to Powershell.exe). %windir%\system32\windowspowershell\v1.0\powershell.exe In the Add arguments (optional) section, type the full path to your script (enclosed in double quotes), e.g. "C:\alert_test.ps1" Tony
May 4th, 2010 4:48am

We must be looking at different things. I am in the Performance Logs and Alerts for Win 2003 R2 server. I tried what you suggested. The only place where the command line arguments allow a string is with the text selection. When I put the path to the ps1 file I got .NET 2.0 errors.
Free Windows Admin Tool Kit Click here and download it now
May 4th, 2010 5:16am

To whom it may concern, this problem was resolved in the original thread: Using a PS Script for Server Alert http://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/2ac78dc6-c6e9-4529-ada4-8a0955a965e9 Thanks.This posting is provided "AS IS" with no warranties, and confers no rights.
May 4th, 2010 6:28am

Ah, I was looking at WS2008 R2. I've not tried it with 2003 R2, but at least it sounds like you've found a workaround. Tony
Free Windows Admin Tool Kit Click here and download it now
May 4th, 2010 6:48am

I must have tried 40-50 combinations of different things and using a batch file as a wrapper for a ps1 script was the only thing that worked. There may be other solutions but I could not find one.
May 4th, 2010 5:32pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics