我正在尝试将所有控制台输出记录到一个文件中。 移动项目 D:\scripts\fileA D:\scripts\fileB -verbose -Force |输出文件 D:\scripts\move.log -Append
如果文件不存在,则正在创建文件。 但是此文件中不存在详细信息和最终的 powershell 错误。 我怎样才能得到这些信息?
最佳答案
管道只捕获成功输出流,不捕获错误和详细流。要同时捕获后者,您需要将其重定向到前者:
Move-Item "D:\scripts\fileA" "D:\scripts\fileB" -Verbose -Force <b>2>&1 4>&1</b> |
Out-File D:\scripts\move.log -Append
参见 Get-Help about_Redirection
获取更多信息。
关于Powershell:输出文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17084917/