powershell - Powershell如何将结果同时输出到多个文件中?

标签 powershell powershell-3.0 powershell-4.0

有没有一种方法可以一次将out-file编码到多个文件?

就像是
{script block} | out-file $file1, $file2, $file3
我想保留几个相同结果的副本。

我测试了几种方法,没有任何效果。

最佳答案

不,Out-File无法做到这一点

但是, Add-Content Set-Content 确实支持-Path参数

上面的链接中的Set-Content的示例也使用通配符对此也有类似的示例。

PS> Get-ChildItem -Path .\Test*.txt

Test1.txt
Test2.txt
Test3.txt

PS> Set-Content -Path .\Test*.txt -Value 'Hello, World'

PS> Get-Content -Path .\Test*.txt

Hello, World
Hello, World
Hello, World


但是,-Path支持数组,因此您只需要更改正在使用的cmdlet,就可以开始比赛了。
{script block} | Set-Content -Path $file1, $file2, $file3

关于powershell - Powershell如何将结果同时输出到多个文件中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55189008/

相关文章:

使用 IF 语句运行命令之前的 Powershell 操作系统检查

xml - 如何使用 Powershell 删除 xml 文件中的 <w :documentProtection . ../> 行?

powershell-3.0 - 在Powershell中选择多列

powershell - 如何在 v2 模式下运行 PowerShell v3 控制台

powershell - 使用powershell删除文件中的NUL字符

PowerShell 如何自动重启服务?

python - 从文本文件中提取数字

Powershell显示弹出窗口并不断更新弹出窗口的while循环体

powershell - 从另一个上下文引用 ScriptBlock 中定义的函数

powershell - 运行powershell脚本时如何避免UAC提示