Another approach, using PowerShell cmdlets, is as follows:
PS C:\PowerShellScripts> set-content -path Test3.txt -value "Hello
world!"
PS C:\PowerShellScripts> get-content -path Test3.txt
Hello world!
PS C:\PowerShellScripts> add-content -path Test3.txt -value "`n"
PS C:\PowerShellScripts> get-content -path Test3.txt
Hello world!
PS C:\PowerShellScripts>
Notice that extra whitespace (more than one line it seems) is added by
the add-content cmdlet.
Andrew Watt MVP
On Wed, 27 Sep 2006 09:14:01 -0700, dreeschkind
<dreeschkind@discussions.microsoft.com> wrote:
>"Jens Schulze" wrote:
>
>> with "$datei | Get-Member" i found that ehr ist es Method AppendText, but
>> how to use them to append a new line at the end of the text-file?
>
>As you can see from the output of Get-Member, the method AppendText returns
>an
>System.IO.StreamWriter object. You can assign that to a variable:
>
>PS> $sw = $datei.AppendText()
>
>You can then see the methods of the StreamWriter by piping it to Get-Member
>again:
>
>PS> $sw | gm
>
>You can write to the StreamWriter using it's methods Write() or WriteLine():
>
>PS> $sw.Write("Ich lerne PowerShell.")
>
>When you're finished you can call the Flush() method to save the changes:
>
>PS> $sw.Flush()
>
>To check the content of the file use Get-Content:
>
>PS> Get-Content $datei
>
>An even shorter solution is to pipe strings to Out-File cmdlet which also
>has an append parameter:
>
>"Test" | Out-File -filePath $datei -append
>
>And you can use shell redirection operators:
>
>"Test" > $datei # overwrite
>"Test" >> $datei # append