【问题标题】:Out-File doesn't write any outputOut-File 不写任何输出
【发布时间】:2017-05-12 16:43:30
【问题描述】:

我有以下问题:

脚本没有在我的 export.txt 文件中写入任何内容,但它确实显示“找到文件!”...

$client = "my-workstation"
$file = "c$\Windows\System32\notepad.exe"
$export = "C:\temp\export.txt"

If(Test-Path "\\$client\$file")
{
   write-host $client | Out-File $export
   write-host "File found!"
}

【问题讨论】:

  • write-host 不返回任何内容,因此没有任何内容写入文件。
  • 如果您想在控制台上查看输出并将其写入文件中,您可以使用 tee-object cmdlet。

标签: windows powershell


【解决方案1】:

Write-Host cmdlet 将消息写入控制台,它将任何内容放入管道,因此您必须省略Write-Host:

$client | Out-File $export

【讨论】:

  • 哦,我明白了.. 谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-17
  • 2021-02-01
  • 1970-01-01
  • 2020-12-22
相关资源
最近更新 更多