powershell - Powershell如何同时将结果输出到多个文件中?
问题描述
有没有一种方法可以一次out-file
处理多个文件?
就像是
{script block} | out-file $file1, $file2, $file3
我想保留几份相同的结果。
我测试了几种方法,没有任何效果。
解决方案
不,Out-File
不能这样做
但是,Add-Content
并且Set-Content
确实支持其-Path
参数
上面链接Set-Content
中的一个示例 for 有一个类似的示例,也使用通配符。
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
推荐阅读
- java - 如何将easymock用于hashmap
- jenkins - Jenkins 多分支管道:从 Jenkinsfile 设置 _job_ 名称
- autodesk-forge - Autodesk forge 中的相位视图,3D 房间
- java - SSL 握手中止:ssl=0xae8414e8:系统调用期间的 I/O 错误,对等方重置连接
- c# - 将 Crystal Reports 与数据集绑定
- php - mysqli_fetch_all 在将数据调用到其他文件时不起作用
- mysql - 什么是 mysql 斗牛士中的“FTS_0000000000002fe2_000000000000694c_INDEX_1.ibd”
- sql-server - 我有患者访问的开始时间和结束时间(在访问表中)。我想为用户(医院团队成员)分配访问
- node.js - 上传前调整图像大小
- python - 将重复数据从行转换为列