PowerShell by Douglas

How To Send Output To A File

Using the *-Content cmdlets. There are four *-Content cmdlets:

  • Add-Content – appends content to a file.
  • Clear-Content – removes all content of a file.
  • Get-Content – retrieves the content of a file.
  • Set-Content – writes new content which replaces the content in a file.

The two cmdlets you use to send command or script output to a file are Set-Content and Add-Content. Both cmdlets convert the objects you pass in the pipeline to strings and then output these strings to the specified file. A very important point here – if you pass either cmdlet a non-string object, these cmdlets use each object’s ToString() method to convert the object to a string before outputting it to the file.

See more at How to send output to a file - PowerShell Community (microsoft.com)

Comments