windows - Call PowerShell Script From Batch File With All Parameters -


this question , this blog post address how pass particular parameters powershell script batch file.

how can 1 pass parameters powershell script? want splat parameters batch file passes arguments through transparently.

edit more context:

i'm using line like:

powershell.exe -command "& '%~dpn0.ps1' '%1' '%2'" 

this works, creates redundancy between files such that, if update powershell script take different arguments, have update batch script well. nice if like:

powershell.exe -command "& '%~dpn0.ps1' '%*'" 

try following:

powershell -file "%~dpn0.ps1" %* 
  • in batch files, %* represents arguments passed.[1]

  • -file parameter use invoke scripts via powershell's cli.

  • all remaining arguments passed through as-is (whereas -command subject them round of interpretation powershell[2] ).

[1] note cmd.exe (batch files) recognize argument embedded whitespace single argument, must enclose in "...".
instance, if wanted pass arguments a , b c batch file file.cmd, you'd have call as
file "b c".
pass embedded " instances, \-escape them; e.g., "\"b c\"" makes powershell see "b c", including double quotes.
if respect these rules, %* - without quoting - passes array of arguments through.
not use "%*" - won't work expected.

[2] in effect, -command causes following arguments joined single space each, , resulting string interpreted as powershell command - is, after arguments parsed rules of cmd.exe (batch files), subject another round of parsing, powershell.
unfortunately, powershell has worked way, behavior obscure, , cause more confusion in unix world, powershell has gone cross-platform - see this github issue.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -