How to pass parameters to powershell command when interpretting script from standard input -


i running powershell script on ssh ssh user@host "powershell -comand - < script.ps1. works expected long start passing arguments.

when put powershell -command - args fails (as documented) '-' specified -command parameter; no other arguments -command permitted.

while other way around powershell args -command - fails with:

the term 'my' not recognized name of cmdlet, function, script file,  or operable program. check spelling of name, or if path included , verify path correct , try again. @ line:1 char:3     + <<<<  args -command -     + categoryinfo          : objectnotfound: (my:string) [], commandnotfounde     xception     + fullyqualifiederrorid : commandnotfoundexception 

i intend put in arbitrary list of parameter without parsing.

edit:

as investigate further, seems doing wrong when command specified explicitly:

(local bash) $ echo '\n' | ssh -i master-key admin@10.8.55.78 '$systemroot/system32/windowspowershell/v1.0/powershell' -command 'write-host \$\(\$args.count\)' "my" "args" 0 args 

it seems passes no arguments printed on console reason. avoiding ssh not seems change anything:

(cygwin) $ $systemroot/system32/windowspowershell/v1.0/powershell -command 'write-host $($args.count)' "my" "args" 0 args 

you can't directly, think can done, if wrap script in scriptblock , pass arguments it:

echo "& { $(cat script.ps1) } 'my' 'args'" | ssh user@host "powershell -command" 

since -command parameter can't handle multiline strings, there way pass in (though not via standard input) using base64 encoded value of -encodedcommand parameter, it's ugly:

ssh user@host "powershell -encodedcommand $((echo "& {"; cat script.ps1 ; echo "} 'my' 'args'") |  iconv -f ascii -t utf-16le | base64 -w0 ; echo -e "\n") 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -