Page 1 of 1

Problem with VBoxManage guestcontrol and powershell

Posted: 13. Feb 2012, 15:01
by StefanH
Hi,

I have a strange behaviour here when trying to execute a powershell command on my guest system using VBoxManage... Hope you can help me.

My goal is to remotely trigger the execution of different scripts on my guest VM and get their stdout and stderr. This works great for arbitrary scripts, e.g. when I execute ipconfig in a cmd shell like

Code: Select all

VBoxManage.exe guestcontrol "ExampleVM" execute --username administrator --password xxx --wait-exit --wait-stdout --image "C:\Windows\System32\ipconfig.exe"
then the remote command executes, returns and I get the output in the same shell like

Code: Select all

C:\Program Files\Oracle\VirtualBox>VBoxManage.exe guestcontrol "ExampleVM" execute --username administrator --password xxx --wait-exit --wait-stdout --image "C:\Windows\System32\ipconfig.exe"

Windows IP Configuration


Ethernet adapter Local Area Connection:

   Connection-specific DNS Suffix  . :
   IPv4 Address. . . . . . . . . . . : 10.1.1.12
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . :

C:\Program Files\Oracle\VirtualBox>
Perfect and exactly what I need so far. However, as soon as I execute a powershell script, e.g. the following very minimalistic one:

Code: Select all

Write-Host "Hello!"
and call it via

Code: Select all

C:\Program Files\Oracle\VirtualBox>VBoxManage.exe guestcontrol ExampleVM" execute --username administrator --password xxx --wait-exit --wait-stdout --image "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" --  C:\TemplateSW.ps1
what happens is:
  • 1) On the guest system a cmd opens in which obviously the script is executed
    2) I see the output "Hello!" in the shell on my host system.
    3) On the guest system the cmd stays open and in the Task Manager I see the powershell process staying alive
    4) On my host system, the VBoxManage.exe never returns. Only if I manually close the cmd shell in the guest, the command in the host returns.
    (Of Course, if I execute the powershell script directly on the guest, it returns as expected)
I started to experiment by using all kind of VBoxManage parameters and all kind of powershell switches. I also tried to put a "cmd / c" in front of the powershell command. Still the same behaviour.
I definitely need the command on the host system to return and I also definitely need the redirected stdout on the host!

Any ideas? I cannot solve out what is the big difference in remote executing a command like ipconfig and a powershell script. :(

My setup is as follows:
Host: W7 64Bit, Virtual Box V 4.1.0 r73009
Guest: Windows Server 2008 R2 Standard

Best regards,
Stefan

Re: Problem with VBoxManage guestcontrol and powershell

Posted: 13. Feb 2012, 16:50
by StefanH
Seems like its a powershell issue. The powershell command line switch

Code: Select all

-inputformat none
is doing the magic... :)

Re: Problem with VBoxManage guestcontrol and powershell

Posted: 13. Aug 2014, 14:31
by JLD
Thanks for the tip! You saved my day.