DX Unified Infrastructure Management

  • 1.  Running Powershell Scripts

    Posted Apr 16, 2014 04:22 PM
      |   view attached

    Hi All,

     

    I am attempting to run PowerShell scripts via a package, set up as shown in the attached image.  The poc1.cmd is executed, which only contains the following line: powershell.exe .\poc1.ps1.  The poc1.ps1 contains the powershell script.

     

    What's happening is, if there's a short powershell script, it executes just fine, but if there's a longer script (maybe 2-3 minutes), it never finishes executing.  Powershell.exe stays running and nothing happens.  If I set this script to recur every hour, then a new Powershell.exe process starts up and stays running each hour.

     

    The script, when run directly from the server, works fine every time, including when executed from poc1.cmd.  Anyone have any ideas as to what I might be doing wrong, or have a suggestion to do it better?

     

    Thanks,

    DS



  • 2.  Re: Running Powershell Scripts

    Posted Apr 16, 2014 07:19 PM

    Hi,

     

    Are you deploying it as a timed probe? Unless you need it for some other reason, you shouldn't need the cmd as wrapper, you could just have powershell.exe as command for it and the script path as argument.

     

    -jon



  • 3.  Re: Running Powershell Scripts

    Posted Apr 16, 2014 08:08 PM

    We are indeed using it as a timed probe, and thanks for the advice on not needing to use a wrapper.  However, I found the issue by logging each stage of the powershell execution to a text file and finding that the connect-viserver command hadn't had user/password parameters passed to it, so it would hang on that step.

     

    Now all I need to find is a way to have an alert pop up if executed jobs hang like this in the future.



  • 4.  Re: Running Powershell Scripts

    Posted Apr 16, 2014 09:58 PM

    How about starting the actual script as a job (start-job) and checking the status with get-job and alerting, killing it when needed? Kind of like wrapper but use jobs instead.

     

    If you need to run it periodically, you could also have logmon or nexec probe run it.

     

    -jon



  • 5.  Re: Running Powershell Scripts

    Posted Apr 29, 2014 10:26 PM

    I haven't run into the timeout problem because my scripts only take a few seconds to run, and my powershell scripts don't need credentials passed to them, but I run them via logmon with the following command:

     

    powershell.exe -executionpolicy remotesigned -File "C:\<path>\<name_of_script>.ps1"

     

    May be worth a try?

     

    -Martin