Skip to content

Instantly share code, notes, and snippets.

@mkouhei
Last active August 30, 2017 22:28
Show Gist options
  • Save mkouhei/f22435f70400162813e809b49ae1260e to your computer and use it in GitHub Desktop.
Save mkouhei/f22435f70400162813e809b49ae1260e to your computer and use it in GitHub Desktop.
$vmname = $one
function Show-VM-Info {
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" showvminfo $vmname
}
function VM-Powered-off? {
Show-VM-Info | Select-String State: | Select-String -quiet 'powered off'
}
function Start-VM {
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" startvm $vmname --type gui
}
function List-VM {
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" list vms
}
function VM-Exist? {
return (List-VM | Select-String -quiet $vmname)
}
if (-Not (VM-Exist?)) {
echo "[error] '$vmname' is not exists."
exit 1
}
if (VM-Powered-off?) {
Start-VM
} else {
echo "VM: '$vmname' has been powered on."
exit 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment