title: Redirecting PowerShell output to text file - different results with new file vs appending
body: <p>I having a weird issue redirecting output to a file. I have tried several different ways to do it, and kept running into formatting issues.</p>
  
  <p>I have the following code as an example that works perfectly:</p>
  
  <pre><code>Get-childitem -Path 'C:\Program Files' | Where-Object{$_.Name -like "*microsoft*"} | 
  
  sort Name -Descending | format-table Name, LastWriteTime &gt;&gt; c:\temp\newfile.txt 
  </code></pre>
  
  <p>This is what the output looks like in the text file:</p>
  
  <pre><code>Name                                                                                 LastWriteTime                                                                       
  ----                                                                                 -------------                                                                       
  Microsoft.NET                                                                        05/07/2015 7:56:29 AM                                                               
  Microsoft Synchronization Services                                                   05/07/2015 7:56:39 AM                                                               
  Microsoft Sync Framework                                                             05/07/2015 7:56:29 AM                                                               
  Microsoft SQL Server Compact Edition                                                 05/07/2015 7:56:29 AM                                                               
  Microsoft Silverlight                                                                05/26/2015 10:18:53 AM                                                              
  Microsoft Policy Platform                                                            05/07/2015 7:38:56 AM                                                               
  Microsoft Office                                                                     05/07/2015 5:48:43 PM                                                               
  Microsoft Application Virtualization Client                                          01/27/2015 6:45:27 PM                                                               
  Microsoft Analysis Services                                                          05/07/2015 7:54:46 AM                                                               
  </code></pre>
  
  <p>It works exactly as I would expect and want it to. However, when I try to do the same thing and append to an existing file, I get strange formatting. Using this code:</p>
  
  <pre><code>Get-childitem -Path 'C:\Program Files' | Where-Object{$_.Name -like "*microsoft*"} | 
  
  sort Name -Descending | format-table Name, LastWriteTime &gt;&gt; c:\temp\existingfile.txt 
  </code></pre>
  
  <p>Produces strangely formatted results when appending to an existing text file. The formatting doesn't come across right here, but this is the closest approximation of what I can get to display here. The actual text file is even more messed up than can be shown here.</p>
  
  <pre><code>This is a test of appending to an existing file
  -------
  This is some previously logged information
  ------
  It doesn't really matter what text is already here
  ------
  
  
  N a m e 
     M i c r o s o f t   S y n c h r o n i z a t i o n   S e r v i c e s
        M i c r o s o f t   S i l v e r l i g h t
           M i c r o s o f t   A p p l i c a t i o n   V i r t u a l i z a t i o n  C l i e n t 
  </code></pre>
  
  <p>So why is this occurring, and how do I get the same results that I get in a new text file when appending to an existing file?</p>