2017-11-11 146 views
1

我写了一个PowerShell脚本来启动/停止VM如下工作但有错误。PowerShell脚本来的VirtualBox虚拟机的saveState和每次

$vmstate = (vboxmanage showvminfo $vma --machinereadable | % { if ($_ -like 'VMState="*"') { $_ } }) 

Write-Host $vmstate 

if ($vmstate -like '*run*') { 
    Write-Host "Wait while "$vma" is powered off (saving state)" 
    vboxmanage controlvm $vma savestate 
} 
else { 
    Write-Host "Wait while "$vma" is started" 
    vboxmanage startvm $vma 
} 

启动VM每次都工作正常。 但是,保存状态仍然有效,但在PS ISE输出窗口中显示此错误。

等待而W2008_21_06_A断电(节能状态)vboxmanage: 0%... 10%... 20%... 30%... 40%... 50%... 60 %... 70%... 80%... 90%... 100%在 C:\ Users \ craig \ My Documents \ vbox.ps1:18 char:5 + vboxmanage controlvm $ vma savestate + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +类别:未指定:(0%... 10%。 ..20%.... 0%... 90%... 100%:字符串)[],RemoteException的 + FullyQualifiedErrorId:NativeCommandError

我得到的印象是它已保存状态在VBoxManage制定结果之前!?!

任何想法?

  • 垂直框v5.1.24
  • 的PowerShell 4.0版
  • 的Windows 8.1

问候,

克雷格

回答

0

我编辑全路径脚本vboxmanage就跑从命令行与powershell -f和错误不会发生。

所以我想这是与ISE有关。

新代码:

$vmstate = (& "C:\Program Files\Oracle\VirtualBox\vboxmanage.exe" showvminfo $vma --machinereadable | % { if ($_ -like 'VMState="*"') { $_ } }) 

Write-Host $vma $vmstate 

if ($vmstate -like '*run*') 
{ 
    # Power off VM before restoring snapshot 
    Write-Host "Wait while "$vma" is powered off (saving state)" 
    & "C:\Program Files\Oracle\VirtualBox\vboxmanage.exe" controlvm $vma savestate 
} 
else 
{ 
    # Start VM 
    Write-Host "Wait while "$vma" is started" 
    & "C:\Program Files\Oracle\VirtualBox\vboxmanage.exe" startvm $vma 
} 

在命令行:

powershell -f "C:\Users\craig\My Documents\vbox.ps1" 

如果有人想分享为何ISE会导致错误不知道。