Fixes the issue of Vagrant is unable to execute Get-WindowsOptionalFeature Command changes 2

Fixes #11932
This commit is contained in:
lyderX05 2020-10-01 16:14:48 +05:30 committed by sophia
parent b0a4109845
commit 88c5e17c5c

View File

@ -141,10 +141,9 @@ module Vagrant
@_windows_hyperv_enabled = -> {
{:"Get-WindowsOptionalFeature" => ["-Online"], :"Get-WindowsFeature" => []}.each do |cmd_name, arguments|
parameters = arguments.join " "
ps_cmd = "$(#{cmd_name} -FeatureName Microsoft-Hyper-V-Hypervisor #{parameters}).State"
if cmd_name == "Get-WindowsFeature"
ps_cmd = "if (Get-Command #{cmd_name} -ErrorAction SilentlyContinue){ $(#{cmd_name} -FeatureName Microsoft-Hyper-V-Hypervisor #{parameters}).State } else { 'Disabled' }"
else
ps_cmd = "$(#{cmd_name} -FeatureName Microsoft-Hyper-V-Hypervisor #{parameters}).State"
end
begin
output = Vagrant::Util::PowerShell.execute_cmd(ps_cmd)