Jeff Wouters's Blog

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

by on Dec.19, 2013, under DuPSUG, PowerShell, Script

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?

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

Yes, as easy as that 🙂

2 Comments for this entry

  • digitalover

    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’ 😉

  • Jeff Wouters

    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