How to Delete Lines From Text File in PowerShell

Written by keith perry
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Delete Lines From Text File in PowerShell
PowerShell is used to program utility operations in the Windows operating system. (Thinkstock/Comstock/Getty Images)

PowerShell is a scripting language from Microsoft for use with the Windows operating system. The language can be used to generate many different utility programs, limited only to your imagination. Manipulation of files, folders and configuration settings are common tasks. Simple programs can be entered at the Powershell command prompt with more complex programs stored in a file. Simple manipulation of content in a text file can be completed at the command prompt.

Skill level:

Other People Are Reading

Things you need

  • PowerShell version 2.0 or later

Show MoreHide


  1. 1

    Open a text editor and create a new text file with alternating lines of text and blank lines.

  2. 2

    Save the text file you created as "C:\file1.txt" and close the text editor.

  3. 3

    Open the PowerShell program from the "Start" button on the Windows task bar, select "All Programs," "Accessories" and "Windows PowerShell."

  4. 4

    Enter the command "(get-content c:\file1.txt) | where {$_ -né ""} | out-file c:\file1.txt" at the PowerShell command prompt.

  5. 5

    Open the text file "C:\file1.txt" with the text editor and note the PowerShell command deleted the blank lines of text.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.