Invoke-Expression to run GDB on remote vm

Welcome Forums General PowerShell Q&A Invoke-Expression to run GDB on remote vm

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 7 years ago.

  • Author
  • #5837

    Points: 0
    Rank: Member

    by Davehal at 2013-04-23 04:18:28


    I'm very new to PowerShell and this is a kind of specialised question, so if I'm asking in the wrong place, please let me know.
    I'm writing a PowerShell script which sends commands to a remote virtual machine which is running linux.
    I am using plink which is just a ssh client to connect to the vm, this connects no problem and I can run simple commands no problem. My issue appears when I try to send commands that run an application on the vm called GDB. This is the Gnome Debugger.
    I dont think my problem is related to plink, gdb or linux, I think it is how I am executing the PowerShell command.
    My problem is that when I run the command to execute the debugger "./rungdb", it runs fine, but my PowerShell script never completes, it just sits there after the Invoke-Expression command and never moves on.

    The code is below, can anyone tell me how to get it to complete the Invoke-Expression statement and move on?

    Thank you, and sorry if this doesn't make sense!

    write-host "Host login attempt..`n";
    $HostAddress = '';

    if($HostAddress -notlike "")
    $myExpression = "& " + $plink + " -pw password -ssh root@" + $HostAddress + " ./rungdb";
    Invoke-Expression $myExpression;

    by DexterPOSH at 2013-04-23 06:47:53

     $myExpression = "& " + $plink + " -pw password -ssh root@" + $HostAddress + " ./rungdb";

    Hi Davehal,

    I think the problem is with the expression you are building "&" is a call operator in PowerShell, it essentially does what Invoke-Expression is doing for you here.
    Try removing the "&" and then run the script from the above line. I am also doubtful about how you are building the expression.

    Try this link to see better ways to call executables in Windows PowerShell

    Hope this helps

    by happysysadm at 2013-04-23 07:09:47

    Dexter is right, you are misusing '&'.

    First I suggest you store your parameters to the linux VM in a putty names session, so you don't have to leave your password in clear in your script.

    Then run something like this:

    [code2=powershell]$command = & .\plink.exe hostname -load sessionname "whatever command"[/code2]


The topic ‘Invoke-Expression to run GDB on remote vm’ is closed to new replies.