Last Updated: June 08, 2016
· superboum

PowerShell: Split command parameters on multiple lines

You might want to split a long function call to Powershell in many lines to improve its readibility.
You should be really careful when doing that

Foo -Many -Long -Parameters

# After
Foo `
 -Many `
 -Long `

Here are the 3 rules to know :
1. You don't split the command with \ (backslash) but with ` (left single quote). Which is really weird.
2. Don't add a space after the left single quote, otherwise it will be ignored, and your command will not be split. If you do that, Powershell will try to call your following parameter as a command.
3. If your call is encapsulated in a function, named Bar, the error will be reported to the line you will call Bar and not where you call Foo...

Filed Under