title: Can I remove/clear some content from a txt file without retrieving the content first?
body: <p>I could be heading down the complete wrong path for what I want to do here so feel free to suggest better options/solutions.</p>
  
  <p>I have a bunch of PowerShell scripts all with their own log files. Logging is done through a function in a separate functions file. I want the oldest lines in the log to start deleting when the file reaches a certain size so it doesn't get too large.</p>
  
  <p>My problem is with how to remove the oldest lines. I don't like the idea of using "Get-Content", removing the top line and then using "Set-Content" to replace the Log file with the same log minus the top line, then repeating until the log is under the specified max size.</p>
  
  <p>For example:</p>
  
  <pre><code>While ((Get-ChildItem $LogFile).Length -gt $MaxLogSize)
  {
      $TopLine,$Remainder = Get-Content $LogFile
      Set-Content -Value $Remainder -Path $LogFile
  }
  </code></pre>
  
  <p>This obviously isn't very sufficient because it has to put the entire log into a variable and then put it back into the log file. </p>
  
  <p>I'm wondering if PowerShell can simply remove the top line in the log file and repeat that until the file is under the max file size? I know there is the "Clear-Content" cmdlet but as far as I know this just clears the whole file.</p>