如何在批处理文件中重定向PowerShell输出(从任务计划程序运行时)?

时间:2017-11-10 18:31:24

标签: powershell batch-file scheduled-tasks

我正在运行任务计划程序中的批处理文件,我将使用Powershell脚本。所以,我有一个批处理文件(TestFD.bat)

Powershell -Command "& {C:\Users\csadouni\Desktop\testFDCOMM.ps1}" > logFDCOM.txt 

如果我从cmd.exe调用批处理文件,我的脚本powershell会在我的SharePoint Online网站上迁移我的文档并且它运行良好(日志文件可以完美地生成)。然后从任务Windows他工作得很好,但任务窗口上的问题似乎无法识别我的输出文件重定向。所以没有生成文件

我尝试了所有解决方案,但没有人解决我的问题。

How to redirect powershell output when run from Task Scheduler?

Executing PowerShell from Windows Task Scheduler

How to execute a PowerShell script automatically using Windows task scheduler?

我不会直接从Scheduler Task运行我的PSscript,因为我需要我的Sharegate传输的输出重定向(Sharegate是一个自动化任务,管理,管理和迁移网站,SharePoint和Office上的内容的产品365),所以,在我有许多其他脚本在我的批处理文件上安排它们之后,我需要我的Powershell迁移输出。 我错过了什么?

感谢任何帮助,谢谢!

1 个答案:

答案 0 :(得分:0)

您可以在PowerShell脚本中将PowerShell输出记录到文件,而不是在调用脚本时记录批处理输出。