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

前端 未结 9 966
我在风中等你
我在风中等你 2020-12-13 12:35

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 i

9条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-13 13:06

    PowerShell 3 onwards allows individual streams (out, verbose, and error) to be redirected. However, Task Scheduler does not understand them. It's PowerShell that does the redirection.

    @cmcginty's solution halfway works, since PowerShell is invoking PowerShell. It only supports standard streams (error and out). If you want to use all streams you need to use:

    Program or script: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

    Argument: -windowstyle minimized –NonInteractive –NoProfile -c "powershell -c path_to_ps1.ps1 4>>verbose.log 5>>debug.log"

    Start in: path_to_ps1

提交回复
热议问题