title: How to append new line text inside a log file using powershell script?
body: <p>I need to pull logs from the original path in C:\ to log directory in D:\Logs but everytime the original path create new log, the script need to append new lines, not replace or rewrite the whole lines.</p>
  
  <p>I already tried this but i guess this replace the whole file and I'm not sure about the Param things.</p>
  
  <pre><code>$SourceFolder       = "C:\ProgramData\Sophos\Sophos Anti-Virus\logs"
  $DestinationFolder  = "D:\Logs\SophosAntivirus"
  
  Function ChangeTabToSpace 
  {
      Param(
          [string] $OldFile = "",
          [string] $NewFile = ""
      )
      $OldText = (Get-Content $OldFile -Raw)
      #Change all tabt \t to space 
      $NewText = ($OldText -replace "`t"," ")
      #Delete the last empty line
      if ($NewText.Length -ge 2) {
          $NewText = $NewText.Substring(0,$NewText.Length-2)
      }
      if (!(Test-path "$NewFile")) {
          New-Item -type file "$NewFile" -force | Out-Null
      }
      #Write-Output $NewText | Out-File -Encoding utf8 "$NewFile"
      [System.IO.File]::WriteAllLines($NewFile, $NewText)
  }
  </code></pre>