powershellscheduled-tasksline-endings

How can I redirect PowerShell output when run from Task Scheduler?


When running a simple PowerShell script from Task Scheduler, I would like to redirect the output to a file.

There is a long thread about this very topic here, yet it's not clear if they reached the most appropriate solution in the end. I'm interested if anyone on Stack Overflow has also solved this problem, and how they did it?


Solution

  • Here is the command that worked for me. I didn't like the idea of redirecting the output in the script, since it would make it difficult to run manually.

    powershell -windowstyle minimized -c "powershell -c .\myscript.ps1 -verbose >> \\server\myscript.log 2>&1"