Line Continuations in PowerShell

With Windows PowerShell it’s so commonplace to hear about and use one-liners….

For example on one line you could do this:
Get-Service | sort Status -Descending | select -First 6 | Format-Table –AutoSize

But to space things out a littler nicer, we could do line continuation using backticks and spread the exact same code onto several lines:

Get-Service | `
sort Status -Descending | `
select -First 6 | `
Format-Table –AutoSize

But, you may not be aware that you can also use the PIPE (|) symbol as a line continuation symbol as well.

Get-Service |
sort Status -Descending |
select -First 6 |
Format-Table –AutoSize

Try them all, they all work the same, use whatever you like best.

 
Comments

No comments yet.

Leave a Reply