PowerShell function to remove empty lines

For some time no I have to remove empty (white) lines from a text file or an array.
Here’s the function I wrote that I would like to share with you… I hope you’ll find it useful 🙂

You can use it like so:

$array = ‘a’,’b’,”,’c’,’d’,”,”,’e’
$Array | Remove-EmptyLines

Remove-EmptyLines -InputObject $array

Remove-EmptyLines -InputObject (Get-Content myfile.txt)

Get-Content myfile.txt | Remove-EmptyLines

Leave a Reply

Your email address will not be published. Required fields are marked *