Scheduling a Powershell script

3

1

I have a powershell script that I want to run as a schedule job.

The script runs great when I execute it manually, but when I run the schedule task, the job fails with the message "could not start"

Schedule job setup:

Run: powershell -command "& 'ScriptName.ps1'" Start in: Run as:

This is scheduled on a Windows Server 2003 and is running powershell 1.

Scott

Posted 2012-06-15T14:54:55.503

Reputation: 93

what is the ampersand for? When I want to debug these, I configure the job to interact with the desktop and start a cmd shell. From there I run the command-line and fix things until it works. The idea being that you can sure permissions and config issues interactively first. – uSlackr – 2012-06-15T16:42:47.090

Answers

2

  1. try to use the full path of ScriptName.ps1

  2. does the script depend on anything in your $Profile? if it does, it may not be loaded when you run as a schedule job, so make sure that you load the module or set up env variables needed.

johnshen64

Posted 2012-06-15T14:54:55.503

Reputation: 4 399

when I tried using the full path, same error. – Scott – 2012-06-19T13:19:51.857

1I ended up needing to use the full path fro both the script and powershell itself. Apparently powershell wasn't in PATH – Scott – 2012-06-21T15:37:04.847

@Scott can you please explain bit more in detail what you did. – Mowgli – 2013-03-15T19:35:58.930

0

I found I needed to including the full path for powershell.exe and the full path for the script in the "Run" textbox: C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe "C:\FULLPATH\MYSCRIPT.ps1"

DBolton

Posted 2012-06-15T14:54:55.503

Reputation: 1