Powershell script runs but does not complete all actions from Task Scheduler


  • Morning all! I've got a really short script that I need to run on a 2008 SBS to restart an application that likes to crash out when not paid enough attention. The code runs correctly from PowerShell ISE and when the PS1 is right-clicked and Run with PowerShell but only the first line is executed when the script is run via a Scheduled Task.

    The code stops the process if running using:

    Stop-Process -Name AccTBk -ErrorAction 'SilentlyContinue'

    This part works fine run from PowerShellISE, or when the script is right-click > Run with PowerShell, or when the .PS1 is triggered by a Scheduled Task.

    The second line of the script starts up the application again (via a shortcut as just firing up the .exe does not open the correct view). The code used is:

    Invoke-Item "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Access Applications\Transaction Broker\Transaction Broker 2.10l.lnk"

    This line works ok from PowerShell ISE and when the PS1 is right-clicked and Run with PowerShell but fails to start the program up from a Scheduled Task. The task is set up as "Run whether user is logged on or not" & "Run with highest privileges". The account I have tested with is the domain Administrator account. The Action is "Start a program" "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" with arguments "-command -NoProfile -NonInteractive "&{C:\Scripts\Restart-AccessTransactionBroker.ps1}"".

    I know the script is not best practices yet and really the solution is to get the app fixed but this would be useful as a stop gap measure. Does anyone have any ideas or need any more info to figure this? Thanks

    Wednesday, February 06, 2013 9:29 AM


All replies

  • Try this settings for your scheduled task:

    Program/script: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

    Add arguments (optional): -noprofile -noninteractive -file C:\Scripts\Restart-AccessTransactionBroker.ps1


    Wednesday, February 06, 2013 3:22 PM
  • Thanks Bill. I didn't really need to be using the -command parameter (plus I just spotted that I had things in the wrong order after removing params to try to see what was going wrong: -command should have been the 3rd param in my list with the command in braces after). The -file param gets the script working again from the task but it still fails to launch the program with the Invoke-Item command. Any further ideas on how I can fix or debug this part? Thanks again
    Thursday, February 07, 2013 8:52 AM
  • Have the script call the command line that the shortcut is pointing to, instead of trying to invoke-item the shortcut.


    Thursday, February 07, 2013 2:40 PM