powershell - 无法从任务计划程序中的 Powershell 命令保存日志文件
问题描述
我正在尝试从 Powershell 任务中创建一个日志文件,Task Scheduler
但是我尝试的任何方法都不起作用。
程序/脚本
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
添加参数
-ExecutionPolicy Unrestricted -File "C:\Users\Boston\script.ps1" > C:\Users\Boston\script.log
这不是将任务的输出保存到文件中。
解决方案
您没有得到任何输出,因为您将重定向作为参数传递给 powershell.exe,因为重定向不是由 cmd 提示符解释的。例如
可执行文件:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
参数列表:
-ExecutionPolicy
Unrestricted
-File
"C:\Users\Boston\script.ps1"
>
C:\Users\Boston\script.log
为了记录输出,最好的方法是在脚本中进行。但是,您可以通过运行脚本来解决它,-Command
然后使用 PowerShell 本身为您重定向输出:
论据:
-ExecutionPolicy Unrestricted -Command "& C:\Users\Boston\script.ps1 > C:\Users\Boston\script.log"
推荐阅读
- java - 如何为给定的字符串模式使用 Java regex 或 Java 流并从中创建映射
- r - Greta中的元素乘法
- html - 引导链接悬停效果未显示
- android - 将 API 数据保存到用户创建的文件夹
- python - 如何在 anaconda 中安装 Pygwr?
- python - 处理 pandas.datetime 类型时出现消息“忽略异常”
- perl - 如何监控属性的变化?(反对改变 /of/ 属性)
- apache-spark - 如何将数据框存储到具有重复键的基础中?
- android - Ionic v1 html5 视频播放器屏幕变黑但音频继续
- python - ValueError: Input 0 is in compatible with layer conv2d_1: expected ndim=4, found ndim=5