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?
1 |
${d:\temp\myfile.txt} = 'This is a some text to put in myfile.txt' |
Yes, as easy as that 🙂
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’ 😉
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.