Page 1 of 1

Trying to disable network adapter

Posted: 2. Jun 2015, 01:06
by ٩(͡๏̯͡๏)۶
Hello,

I'm in the process of disabling the network adapters on all of our virtual machines and I would like to create a script that does this for me. We are a Mac environment with Windows and Linux VMs. So far I have:

for i in `VboxManage list vms`
do
VboxManage modifyvm $i --nic1 none
done

It works in that it turns off the network adapters on all VMs, however the output in Terminal yields a bunch of errors:

VBoxManage: error: Could not find a registered machine named '"Ubuntu'
VBoxManage: error: Details: code VBOX_E_OBJECT_NOT_FOUND (0x80bb0001), component VirtualBox, interface IVirtualBox, callee nsISupports
VBoxManage: error: Context: "FindMachine(Bstr(a->argv[0]).raw(), machine.asOutParam())" at line 464 of file VBoxManageModifyVM.cpp
VBoxManage: error: Could not find a registered machine named '10.10"'

I was wondering if there were a better, less error-filled way of doing this.

Thanks!

Re: Trying to disable network adapter

Posted: 2. Jun 2015, 09:17
by Martin
Looks like you have VMs with blanks in the name. Try enclosing the name parameter with " ".

Re: Trying to disable network adapter

Posted: 5. Jun 2015, 15:10
by socratis
Actually, it's not just the spaces in the name. If you do a "VBoxManage list vms" you'll get both the name and the UUID in a single line (which without proper parsing is going to lead to errors). Like this example:
Machine:~ username$ VBoxManage list vms
...
"_LiveCDs" {00e5351f-a334-40a8-a485-aa0d1b92de36}
"Doudou Linux" {114216de-bade-4218-b087-d745325533dc}
...
You'll need to parse the output in order to get the names just right. Below is the bash script that I use. Copy-paste it, save it in a bash script, like "ANYTHING.sh", change it so that it's executable (chmod +x ANYTHING.sh) and execute it in Terminal.
IFS=$'\t\n'; \
for i in `VBoxManage list vms | cut -d'"' -f2`; \
  do VBoxManage modifyvm "$i" <YourModificationHere>; \
done