将测试路径输出重定向到文本文件 [英] redirecting test-path output to text file
本文介绍了将测试路径输出重定向到文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
txt 文件只是一堆 UNC 路径,我试图在验证测试路径后从这个文本文件中获取一个 UNC 路径列表,并将其放入另一个文本文件中.它会在屏幕上显示经过验证的路径,但不会填充文本文件.
The txt file is just a bunch of UNC paths, i am trying to get a list of UNC paths from this text file put into another text file after the test-path is validated. it shows the validated paths on screen but the text file does not populate.
$cfgs = Get-Content .\cfgpath.txt
$cfgs | % {
if (Test-Path $_) { write-host "$_" | Out-File -FilePath c:\temp\1.txt -Append }
}
推荐答案
Write-Host
只写到控制台.我相信你想要的是Write-Output
.
Write-Host
only writes to the console. I believe what you want there is Write-Output
.
$cfgs = Get-Content .\cfgpath.txt
$cfgs | % {
if (Test-Path $_) { write-output "$_" | Out-File -FilePath c:\temp\1.txt -Append }
}
此外,您可以省略 Write-Output
也可以.
Additionally you can just omit the Write-Output
and that works too.
$cfgs = Get-Content .\cfgpath.txt
$cfgs | % {
if (Test-Path $_) { "$_" | Out-File -FilePath c:\temp\1.txt -Append }
}
这篇关于将测试路径输出重定向到文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文