Splitting Long Lines

by Jun 2, 2015

To improve readability, you can break PowerShell lines into separate lines.

Get-Service | Where-Object { $_.Status -eq 'Running' }

Get-Service | 
  Where-Object { $_.Status -eq 'Running' }

After a pipeline symbol, you can always add a line break. You can also add line breaks safely after an opening brace, and before a closing brace:

Get-Service | 
  Where-Object { 
    $_.Status -eq 'Running' 
  }

If you want to break a line someplace else, add a backtick character before the line break:

Get-Service | 
Where-Object `
{ 
  $_.Status -eq 'Running' 
}

Twitter This Tip! ReTweet this Tip!