在Windows 10上使用Hyper-V时出现的Vagrant错误

5

升级到Windows 10后运行以下操作:

$ vagrant up

我们收到以下错误消息。
An error occurred while executing a PowerShell script. This error
is shown below. Please read the error message and see if this is
a configuration error with your system. If it is not, then please
report a bug.

Script: get_vm_status.ps1
Error:

C:\HashiCorp\Vagrant\embedded\gems\gems\vagrant-1.7.4\plugins\providers\hyperv\scripts\get_vm_status.ps1 : Unable to
find type [Microsoft.HyperV.PowerShell.VirtualizationOperationFailedException].
At line:1 char:1
+ &('C:\HashiCorp\Vagrant\embedded\gems\gems\vagrant-1.7.4\plugins\prov ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Microsoft.Hyper...FailedException:TypeName) [get_vm_status.ps1], Ru
   ntimeException
    + FullyQualifiedErrorId : TypeNotFound,get_vm_status.ps1

使用 Vagrant 1.7.4 版本。
有任何想法吗?

Windows 10在Hyper-V方面存在一些问题。您能否从Hyper-V管理器中创建一个新的虚拟机并尝试启动它? - juliano.net
我刚刚遇到了同样的错误。奇怪的是,我最初并没有遇到这个问题。我没有安装任何有关vagrant、hyper-v、Windows、WMF/PowerShell等方面的更新。自从上一次成功使用vagrant以来,我甚至没有重新启动过电脑;我甚至使用的是同一个命令提示符。太奇怪了。 - briantist
4个回答

14

我在Windows 10企业版上进行了Vagrant 1.7.4的全新安装(第一次使用Vagrant),遇到了同样的问题。

最新版本的PowerShell中,VirtualizationOperationFailedException已被替换为VirtualizationException

我将C:\ HashiCorp \ Vagrant \ embedded \ gems \ gems \ vagrant-1.7.4 \ plugins \ providers \ hyperv \ scripts \ get_vm_status.ps1的第15行从以下内容更改为:

} catch [Microsoft.HyperV.PowerShell.VirtualizationOperationFailedException] {
} catch [Microsoft.HyperV.PowerShell.VirtualizationException] {

现在我能够使用 vagrant up 和 vagrant status 命令而没有错误了。这显然不是长期解决方案,但它让事情重新开始运行了。可能还有其他脚本出了问题,但我还没有遇到过。


我也在使用Vagrant 1.7.2时遇到了这个问题,这个修复方法同样适用,使用你的错误路径来获取get_vm_status.ps1的正确位置。 - Tisch

1

在销毁并重新创建虚拟机后,我遇到了同样的错误。

我删除了.vagrant/machines/hyperv文件夹,一切都正常了。


谢谢。对我在Vagrant 1.8.1上有所帮助。 - Ololo

0
如果@jeff-r的解决方案对你不起作用,你可以尝试更改:
} catch [Microsoft.HyperV.PowerShell.VirtualizationOperationFailedException] {

to:

} catch [Exception] {

注意,它也可能会引起一些副作用。


0

在 Windows 10 上,您必须禁用 "Hyper-V" 才能运行 Vagrant/VirtualBox。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接