Creating a file and adding content to that file in PowerShell

The first step in this example is to create the file.

New-Item -ItemType file -Path c:\temp\file.txt

In this example I am going to assign some text to a variable then I am going to add that content to the file

You do this with the Add content command

add-content -Value $x -Path C:\temp\file.txt