将输出写入PowerShell中的文本文件 [英] Write output to a text file in PowerShell

查看:800
本文介绍了将输出写入PowerShell中的文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用以下代码比较两个文件:

 比较对象$(Get-Content c:\ $(Get-Content c:\ user\documents\List2.txt)

如何将这个输出写入一个新的文本文件?我已经尝试过使用echo命令,但是我不太了解它的语法。 使用<$ c $ 解决方案 c> Out-File cmdlet

 比较对象... | Out-File C:\filename.txt 

或者,添加 -Encoding utf8 Out-File 作为默认编码对于许多用途来说并不是很理想。


I've compared two files using the following code:

Compare-Object $(Get-Content c:\user\documents\List1.txt) $(Get-Content c:\user\documents\List2.txt) 

How can I write the output of this to a new text file? I've tried using an echo command, but I don't really understand the syntax.

解决方案

Use the Out-File cmdlet

 Compare-Object ... | Out-File C:\filename.txt

Optionally, add -Encoding utf8 to Out-File as the default encoding is not really ideal for many uses.

这篇关于将输出写入PowerShell中的文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆