Update Windows Hyper-V check

Checks only if the Hyper-V hypervisor is enabled instead of all
Hyper-V features. This will allow detection where Hyper-V is in
use for things like ApplicationGuard.

Uses both Get-WindowsOptionalFeature and Get-WindowsFeature to
support check on server and non-server version.
This commit is contained in:
Chris Roberts 2018-04-27 14:13:34 -07:00
parent b75732416c
commit a997a27b57
1 changed files with 6 additions and 3 deletions

View File

@ -107,9 +107,12 @@ module Vagrant
return @_windows_hyperv_enabled if defined?(@_windows_hyperv_enabled)
@_windows_hyperv_enabled = -> {
ps_cmd = "$(Get-WindowsOptionalFeature -FeatureName Microsoft-Hyper-V-All -Online).State"
output = Vagrant::Util::PowerShell.execute_cmd(ps_cmd)
return output == 'Enabled'
["Get-WindowsOptionalFeature", "Get-WindowsFeature"].each do |cmd_name|
ps_cmd = "$(#{cmd_name} -FeatureName Microsoft-Hyper-V-Hypervisor).State"
output = Vagrant::Util::PowerShell.execute_cmd(ps_cmd)
return true if output == "Enabled"
end
return false
}.call
return @_windows_hyperv_enabled