Requested Changes Updated on Fixes
Fixes the issue of Vagrant is unable to execute Get-WindowsOptionalFeature Command changes 2 Fixes #11932
This commit is contained in:
parent
88c5e17c5c
commit
a7d87498ed
@ -139,18 +139,20 @@ module Vagrant
|
||||
return @_windows_hyperv_enabled if defined?(@_windows_hyperv_enabled)
|
||||
|
||||
@_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' }"
|
||||
end
|
||||
check_commands = Array.new.tap do |c|
|
||||
c << "(Get-WindowsOptionalFeature -FeatureName Microsoft-Hyper-V-Hypervisor -Online).State"
|
||||
c << "(Get-WindowsFeature -FeatureName Microsoft-Hyper-V-Hypervisor).State"
|
||||
end
|
||||
check_commands.each do |ps_cmd|
|
||||
begin
|
||||
output = Vagrant::Util::PowerShell.execute_cmd(ps_cmd)
|
||||
return true if output == "Enabled"
|
||||
rescue Errors::PowerShellInvalidVersion
|
||||
logger.warn("Invalid PowerShell version detected during Hyper-V enable check")
|
||||
return false
|
||||
rescue Errors::PowerShellError
|
||||
logger.warn("Powershell command not found or error on execution of command")
|
||||
return false
|
||||
end
|
||||
end
|
||||
return false
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user