【问题标题】:How do I write this script's results to a file?如何将此脚本的结果写入文件?
【发布时间】:2015-01-24 14:31:43
【问题描述】:

我正在学习 powershell 时的基本问题。目前我有一个脚本,它以一种干净的格式给我一个目录的输出。我想将结果写入文件而不是控制台。我似乎无法弄清楚 Out-File 的正确用法。我已经在脚本中尝试过,并在运行时尝试将其作为扩展。任何帮助将不胜感激。

get-childitem "A:\data\set1" -recurse | where {$_.extension -eq ".mp3"} | % {
 Write-Host $_.FullName}

【问题讨论】:

    标签: powershell directory output


    【解决方案1】:

    您不需要使用 Write-Host:

    get-childitem "A:\data\set1" -recurse | 
      where {$_.extension -eq ".mp3"} | 
      % {$_.FullName} | 
      Out-File ./list.txt
    

    【讨论】:

    • 太棒了!感谢您的快速回复。
    猜你喜欢
    • 2017-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多