[英]Have write-host output to a file in Powershell
Okay so I'm working in Powershell and am trying to have "write-host" output to a file. 好的,所以我正在Powershell中工作,并尝试将“写入主机”输出输出到文件中。 Here is the code I'm working with right now
这是我现在正在使用的代码
Function CreateNugetPackage {
Param(
[String] $File
)
Process {
$retCode = 0
write-verbose "Getting version of $file..."
$version = (Get-Item $File).VersionInfo.FileVersion
$id = $file.Substring(0, $File.LastIndexof('.'))
$filepath = Get-ChildItem "$File"
$OriginalFilename = (Get-Item $File).VersionInfo.OriginalFilename
write-verbose "$id"
write-verbose "$filepath"
$id > test.txt
write-host $filepath >> test.txt
So the $id generates the name of the file without the extension and what I'm trying to do with the $filepath is have it output the host to the test.txt file. 因此,$ id生成不带扩展名的文件名,而我试图用$ filepath进行的操作是将主机输出到test.txt文件。 I've tried doing "write-output $filepath >> test.txt" but that didn't work the way I wanted it to.
我已经尝试过执行“写入输出$ filepath >> test.txt”,但这并没有达到我想要的方式。 Instead of outputing the host it outputted
而不是输出主机,而是输出
Directory: C:\Users\mhopper\Documents\CreateNugetPackage
Mode LastWriteTime Length Name
---- ------------- ------ ----
-ar-- 10/22/2014 9:17 AM 5534208 AjaxControlToolkit.dll
instead of just "C:\\Users\\mhopper\\Documents\\CreateNugetPackage\\AjaxControlToolkit.dll" 而不只是“ C:\\ Users \\ mhopper \\ Documents \\ CreateNugetPackage \\ AjaxControlToolkit.dll”
Any help would be appreciated thank you! 任何帮助将不胜感激,谢谢!
您不能重定向来自Write-Host
的输出(它不会填充输出流并且无法通过管道传输)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.