Powershell:输出文件

标签 powershell

我正在尝试将所有控制台输出记录到一个文件中。 移动项目 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/

相关文章:

logging - powershell 中的 netsh 命令输出日志记录

windows - 如何使用硬编码密码修复 PowerShell 中 WinSCP SFTP 脚本中的安全性

powershell - New-SelfSignedCertificate 不会在 Windows 7 上运行

引号中的 Powershell 哈希表

windows - Powershell脚本在ie浏览器中打开多个url

windows - 将小的 PS 脚本转换为 .BATch 文件中的长行

powershell - 如何将字符串作为非字符串传递给 powershell 中的命令?

powershell - 为什么 PowerShell 5 在重命名后仍在寻找旧的 PowerShell Gallery 路径?

powershell - 如何检索原始的、未解析(未扩展)的注册表值?

sql - Powershell 对 Excel 工作簿进行多个 SQL 查询