locked
SCOM 2007 R2 - Monitor recovery task - powershell script does not execute RRS feed

  • Question

  • I'm trying to run a powershell script as a recovery task for a custom performance monitor.  The monitor works correctly and when I setup a the recovery script as vbscript it runs just fine.  I'm just doing a little test to write a file and the powershell doesnt execute at all.  Powershell is installed on the test server and the powershell script runs fine when run on the server locally.  Under the recovery task properties on the script tab I feed it a filename of TestPowershell.ps1 and put my script in the script field below.  I give it no parameters.  The vbscript executed fine like this (except the filename was TestVB.vbs).  Anybody know what i'm doing wrong?  I dont want to have to copy the script to all my servers and then write a command line recovery task to kick it off.  I'd like it to work like the way VBScript does.

    Thursday, January 20, 2011 9:51 PM

Answers

  • Yes.  This is a "get out the rubber gloves" moment.  You can see examples on Steve Wilson's site - authormps.com
    Microsoft Corporation
    • Marked as answer by Daniel Kerr Thursday, January 27, 2011 3:28 PM
    Wednesday, January 26, 2011 12:21 AM

All replies

  • The answer by Mike Eisenstein may be helpful here....http://www.eggheadcafe.com/software/aspnet/34270411/console-task--how-to-run-custom-ps-script.aspx

    Sounds like a permissions problem

    Cheers,

    John Bradshaw

    Friday, January 21, 2011 9:57 AM
  • Another possibility is that the PowerShell execution policy is blocking the ps1 script file.

    Try running PowerShell.exe with the  -ExecutionPolicy Unrestricted

    Matt


    Matt White
    ( http://systemcenterblog.hardac.co.uk/ )
    Friday, January 21, 2011 10:22 AM
  • My first thought was to make sure I had it setup correctly before checking other issues.  In the health explorer I can dig down to my monitor and under the Diagnostic and Recovery Options I can see it says the task ran successfully with no output (I shouldnt have said it doesnt run at all).  Problem is if it did run successfully it would have created a file on the root of C (as thats all the script does).  I checked the server that the monitor is scoped to and the file does not exist.  Any help on making sure the script is setup correctly or maybe a way I can see any sort of error code or output would be really helpful.  It could be a permissions problem.  I did try putting "-ExecutionPolicy Unrestricted" in the parameters - no effect.  I also looked at that link but I dont think I'm understanding what the solution is.  I just need a little output or something to go off of.  I dont see anything in the eventlogs either.  Is there any other information I can provide?  It was so easy to do with VB, just wish powershell would be the same - I have to be missing something.

    Monday, January 24, 2011 8:18 PM
  • One thing you want to keep in mind with PS is that it doesn't run automatically. Because of the potential power of PS, MS wanted to ensure that you deliberately invoke the script.   You can kick off a BAT file which calls PS and runs the script.  powershell -command "& 'C:\yourscript.ps1'"

     

    Monday, January 24, 2011 8:26 PM
  • Yeah, I realize that is a potential solution for a command line recovery, however I dont want to have to copy this script(and others) to all of our servers ahead of time.  I thought SCOM 2007r2 supported powershell recovery scripts.  With my vb example it was very easy to feed the wizard a vb file name and the vb script body and it ran.  Are you saying I cant do the same thing just with a powershell file name and a powershell script body?
    Monday, January 24, 2011 8:42 PM
  • There is a <Files> element in the MP that lets you embed file data that would then be propagated automatically by the agents when the script needs to be run.
    Microsoft Corporation
    Monday, January 24, 2011 10:09 PM
  • Dan, that sounds promising but I don't know how to use that element.  Would I need to directly edit the management pack to make use of this?  How would you set this up?  I'll search around and see if I can find an answer, but i'd be interested if you had some steps.
    Tuesday, January 25, 2011 8:28 PM
  • Yes.  This is a "get out the rubber gloves" moment.  You can see examples on Steve Wilson's site - authormps.com
    Microsoft Corporation
    • Marked as answer by Daniel Kerr Thursday, January 27, 2011 3:28 PM
    Wednesday, January 26, 2011 12:21 AM
  • Ugggg.  As I've spent way to much time on this already.  I'll be re-writing the script in vb.  I wish the GUI could handle powershell.  Thanks for the answer and the resource.
    Thursday, January 27, 2011 3:32 PM