管道连接到多个位置-PowerScript [英] Piping to More Than One Location - PowerScript
本文介绍了管道连接到多个位置-PowerScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想做这样的事情-
"Error array cleared." | Out-File $ErrorLog $InfoLog -Append
但是它不起作用.无需编写另一行以将其输出到另一个文件,是否可以做到这一点?
However it's not working. Is this possible without writing another line to output it to the other file?
推荐答案
一种方法是使用像这样的简短函数:
One way is with a short function like this:
function Out-FileMulti {
param(
[String[]] $filePath
)
process {
$text = $_
$filePath | foreach-object {
$text | out-file $_ -append
}
}
}
示例:
"Out-FileMultiTest" | Out-FileMulti "test1.log","test2.log"
(将字符串"Out-FileMultiTest"同时写入test1.log和test2.log)
(Writes the string "Out-FileMultiTest" to both test1.log and test2.log)
这篇关于管道连接到多个位置-PowerScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文