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

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

问题描述

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

I've compared two files using the following code:

Compare-Object $(Get-Content c:userdocumentsList1.txt) $(Get-Content c:userdocumentsList2.txt) 

如何将其输出写入新的文本文件?我试过使用 echo 命令,但我不太了解语法.

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.

推荐答案

使用 Out-File cmdlet

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

可选地,将 -Encoding utf8 添加到 Out-File 中,因为默认编码对于许多用途来说并不是很理想.

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

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

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