PowerShell – A quick way to write content plain text to a file

PowerShell offers many ways to accomplish a task.
Writing text to a file can be done by using Out-File or Add-Content… or those are the most commenly used ways by the IT Pro’s.
What if I told you there is an easier way?

Yes, as easy as that 🙂

6 comments

  1. digitalover says:

    Only thing that doesn’t work this way is using variables ex ${$env:tempmyfile.txt} = ‘This is a some text to put in myfile.txt’ 😉

  2. Jeff Wouters says:

    Correct, this is only the action to put it into a file.
    If you want the content to also be put into a variable:

    $Var = ${d:\temp\myfile.txt} = ‘This is a some text to put in myfile.txt’

    Using the variable inside the path is indeed not possible the way you’ve tried.

Leave a Reply

Your email address will not be published. Required fields are marked *