I have some PowerShell scripts that accept many long parameters, like,
myScript.ps1 -completePathToFile "C:\...\...\...\file.txt" -completePathForOutput "C:\...\...\...\output.log" -recipients ("me@me.com") -etc.
I can’t seem to make PowerShell run such scripts unless all the parameters are on a single line. Is there a way to invoke the script more like this?
myScript.ps1
-completePathToFile "C:\...\...\...\file.txt"
-completePathForOutput "C:\...\...\...\output.log"
-recipients (
"me@me.com",
"him@him.com"
)
-etc
The lack of readability is driving me nuts, but the scripts really do need to be this parametric.
PowerShell thinks the command is complete at the end of the line unless it sees certain characters like a pipe, open paren or open curly. Just put a line continuation character “ ` at the end of each line but make sure there are no spaces after that continuation character:
If you’re on PowerShell 2.0 you can also put those parameters in a hashtable and use splatting e.g: