title: How do I delete a line from a text file in powershell?
body: <p>Suddenly I have the urge to finally get into powershell. Right now I have a way to import a text file, create a text file, and add to a file, but is there a way to delete elements from a file? For example if I have a text file:</p>
  
  <p><strong>test.txt</strong></p>
  
  <pre><code>Quick
  Brown
  Fox
  </code></pre>
  
  <p>I can import the file with 
  $textFile = Get-Content -Path ".\test.txt"</p>
  
  <p>and I can print each element and add them to a new file with </p>
  
  <pre><code>foreach($line in $textFile)
  {
      Write-Host $line
      Add-Content -Path ".\output.txt" -Value $line
  }
  </code></pre>
  
  <p>But how can I delete or remove an element (a line) from the <code>test.txt</code> file? I googled for a solution but I only get results for conditions in which someone wants to <a href="https://stackoverflow.com/questions/9223460/remove-empty-lines-from-text-file-with-powershell">delete a blank line</a>, <a href="https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/remove-item?view=powershell-7" rel="nofollow noreferrer">deleting the entire file</a>, or <a href="https://stackoverflow.com/questions/668907/how-to-delete-a-line-from-a-text-file-in-c">how to do it in C#</a>. I thought it would be as intuitive as the previous commands..</p>
  
  <p>Thanks for the feedback!</p>