locked
Powershell process starts but doesn't do anything (hangs) RRS feed

  • Question

  • There's probably a simple answer to this but I'm too close to see it.

    There's an compiled java program I'm using (don't have source) that allows me to define a custom program that I use to further the results I need.  The application generates a file, stores it, and then calls my custom program.  This can be done manually or automatically via a service.  The custom program I've entered is

    custom.cmd Filename

    custom.cmd consists of

    @echo off

    C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File C:\work\MyPSScript.ps1 %*

     

    This script does a lot of things (too large to post here) but it runs fine when I run it manually from the application.

    If the application starts it automatically via its service it starts fine.  I can see that it started in task manager, IE:   C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File C:\work\MyPSScript.ps1 "C:\FileFolder\passedfilename" as well as the cmd.exe.  At that level everything looks good.

    That's it though - powershell hangs there.  It doesn't do anything defined in the script.  The process will sit there indefinitely.  I have to reboot or kill the process.  Here's some of the troubleshooting steps I've done:

    set-executionpolicy unrestricted as administrator and as my working admin account.

    Changed the login account for the service to my working admin account.

    Modify the ps1 script to write to a text file when it starts - doesn't write to the file when started by the service.

    Added the 1st line in the powershell script as: start-transcript -Path "C:\work\powershelllog.txt" -Force

    This works as expected when run manually, no results whatsoever when started from the service.

    Tried using the -NoLogo -NonInteractive and -NoProfile options.

    Tried redirecting the powershell output by changing the line in custom.cmd to

    C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File C:\work\MyPSScript.ps1 %* >C:\work\log.txt 2>&1

     

    If I could get powershell to tell me what is wrong I could fix it - but it won't tell me.  help!

    Friday, December 2, 2011 7:07 PM

Answers

  • I abandoned trying to get it to work - I am running the script via the scheduler.
    • Marked as answer by DennisT. _ Tuesday, December 20, 2011 10:21 PM
    Monday, December 12, 2011 8:55 PM

All replies

  • I was studying my task manager and doing some testing and realized that when my PS script is run manually from the java application the powershell process also hangs, but it hangs after the end of the program.  IE the start & stop transcript work and stop-transcript is the last statement in the PS script.
    Friday, December 2, 2011 7:47 PM
  • Hi,

    I'm not sure there is enough information in your question to be able to provide a definitive answer. I recommend writing a short script (just enough code to reproduce the problem but no more) and the specifics of the scheduled task's parameters. In other words, give us the ability to reproduce the problem without needing your specific configuration and environment. We can't see your screen.

    Bill

    • Marked as answer by Bill_Stewart Tuesday, December 20, 2011 10:16 PM
    • Unmarked as answer by DennisT. _ Tuesday, December 20, 2011 10:20 PM
    Monday, December 12, 2011 7:45 PM
  • You cannot run PowerShell as a service.  You can run it as a task under correct credentials.

     


    jv
    Monday, December 12, 2011 8:05 PM
  • I abandoned trying to get it to work - I am running the script via the scheduler.
    • Marked as answer by DennisT. _ Tuesday, December 20, 2011 10:21 PM
    Monday, December 12, 2011 8:55 PM
  • You cannot run PowerShell as a service.  You can run it as a task under correct credentials.

     


    jv

    Sure you can.  I have a service running on one of my servers that is a powershell script.
    Monday, December 12, 2011 8:56 PM
  • There are some thngs thta will not work and some that may.

    If you cannot post your script then we cannot be of much help.

     


    jv
    Monday, December 12, 2011 9:45 PM