[powershell] Write output to a text file in PowerShell

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.

This question is related to powershell file-io

The answer is

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.

Similar questions with powershell tag:

Similar questions with file-io tag: