Sever 2008 R2 Powershell Script runs manually, but not as a scheduled task

Posted by Aeisor on Server Fault See other posts from Server Fault or by Aeisor
Published on 2013-05-04T10:15:40Z Indexed on 2013/06/25 22:23 UTC
Read the original article Hit count: 193

I have a Powershell script that runs manually using the Powershell ISE; However, when run as a scheduled task using an administrator's credentials the task does not run with the expected results.

The script:

$request=new-object System.Net.WebClient $request.DownloadFile("...url...", "C:\path\to\file.csv")

The administrator user has Full Control of both the script and the folder it is writing to. The url exists and responds in a reasonable time (<1s).

If I run the task manually the status is 0x41301 ("Currently Running") until I eventually end it. I have set the task up using both of these methods:

  1. Start a Program: C:\path\to\PS.PS1
  2. Start a Program: C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe with additional options -noninteractive -command "C:\path\to\PS.PS1"

Using option 1, the task history shows it has opened an instance of notepad.exe but never terminates it. Using option 2 it completes the task but doesn't download / create the file.

I have used Set-ExecutionPolicy Unrestricted as this is not a signed script.

Any ideas?

© Server Fault or respective owner

Related posts about windows-server-2008-r2

Related posts about powershell