Sever 2008 R2 Powershell Script runs manually, but not as a scheduled task
- by Aeisor
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:
Start a Program: C:\path\to\PS.PS1
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?