首页 > 解决方案 > 通过批处理脚本调用时,Powershell 脚本中的 Out-File 无法更新或创建?

问题描述

我有一个 PowerShell 脚本,它通过 Out-File 命令将某些信息记录到文件中:

"text to be logged" | Out-File $logFile -Append

当 PowerShell 脚本直接运行时,日志文件的创建/更新没有任何问题。通过以下命令通过批处理脚本调用此 PowerShell 脚本(由于我使用的工具仅接受批处理脚本作为输入):

PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process PowerShell -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File """"%powerShellScriptPath%"""" """"%argOne%"""" """"%argTwo%""""' -Verb RunAs}";

我在上面实施的命令是基于在这个答案中找到的实现。

通过批处理脚本调用时,永远不会创建/更新日志文件。PowerShell 脚本在幕后毫无问题地执行其所有职责,它根本无法创建日志文件或用数据填充它......

标签: powershellbatch-file

解决方案


推荐阅读