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

cmcginty picture cmcginty · Dec 9, 2012 · Viewed 51.4k times · Source

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?

Answer

cmcginty picture cmcginty · Dec 11, 2012

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"