2

I want to execute a command from powershell, which in turn executes a command on a foreign server, using plink. But this only works if I do not have ' or " in the command, otherwise Powershell jumps in and prints exceptions.

Example:

Invoke-Expression "$plinkPath -ssh $username@$host 'echo well...; echo hello'"

gives

well...
hello

. But what if I want to echo both ' and ", say

Invoke-Expression "$plinkPath -ssh $username@$host 'echo well...; echo hello, my "friend" 'brutus'!'"

to get

well...
hello, my "friend" 'brutus'!

?

Edit: Extension, I want to have a $.

well...
hello, my "friend" 'brutus', you $insult!
Bowi
  • 1,637
  • 2
  • 20
  • 41

1 Answers1

0

For completeness, this is the command for the response I asked for:

& $plinkPath -ssh $username@$host "echo well...; echo Hello, my \\\`"friend\\\`" \'brutus\', you \`$insult!"

It brings

well...
Hello, my "friend" 'brutus', you $insult!
Bowi
  • 1,637
  • 2
  • 20
  • 41