tags:

views:

776

answers:

4

I have created a Powershell script and set it up to run within a .bat file. When I click on the .bat file the Powershell script runs like a champ. I then set up the .bat file to be run as a scheduled task. Again it works like a champ when I right click on it and launch it interactively. Problem is it fails when the task scheduled to run unattended in the evening.

Not sure if this matters but I am using Powershell v.1 on Windows 2003 Server 64.

Thanks in advance for your help.

========================================== The status on the scheduled task is "Could not start". Perhaps fails was the wrong choice of words because the task probably doesn't even start running.

The task is set up to run as my user and I am set up as a local administrator on the box.

A: 

Is the task set to run with your useraccount or as System? Check the access rights on cmd.exe and powershell.exe.

Also if you go to the sheduled tasks you can do a 'view log' in the advanced menu to check for error messages.

chris
A: 

Just a guess, but could it be something to do with the account/security context from which the script is running? If it's running on the System account, then that could certainly be a problem. (I suspect it's just running on your user account however.) Check that all your path variables are set correctly when the script runs, for a start. Otherwise, could you perhaps provide any more information on how exactly it fails (i.e. any error messages)?

Noldorin
+2  A: 
Sung Meister
A: 

Maybe the current directory is not set as you expect when running from the task manager. Try running your bat file from the command line, while you are not in the same directory as the file (and your .ps1 script) are.

Otherwise: check permissions.

thijs