Skip to content

Commit d9c07c7

Browse files
Added Get-CimInstance with deprecated Get-Wmiobject to detect Hyper-V availability
1 parent d11e45a commit d9c07c7

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

pkg/minikube/registry/drvs/hyperv/hyperv.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,19 @@ func status() registry.State {
9191
ctx, cancel := context.WithTimeout(context.Background(), 8*time.Second)
9292
defer cancel()
9393

94-
cmd := exec.CommandContext(ctx, path, "-NoProfile", "-NonInteractive", "@(Get-Wmiobject Win32_ComputerSystem).HypervisorPresent")
94+
cmd := exec.CommandContext(ctx, path, "-NoProfile", "-NonInteractive", "@(Get-CimInstance Win32_ComputerSystem).HypervisorPresent")
9595
out, err := cmd.CombinedOutput()
9696

9797
if err != nil {
98-
errorMessage := fmt.Errorf("%s failed:\n%s", strings.Join(cmd.Args, " "), out)
99-
fixMessage := "Start PowerShell as an Administrator"
100-
return registry.State{Installed: false, Running: true, Error: errorMessage, Fix: fixMessage, Doc: docURL}
98+
cimError := fmt.Errorf("%s failed:\n%s ", strings.Join(cmd.Args, " "), out)
99+
cmd := exec.CommandContext(ctx, path, "-NoProfile", "-NonInteractive", "@(Get-Wmiobject Win32_ComputerSystem).HypervisorPresent")
100+
out, err := cmd.CombinedOutput()
101+
if err != nil {
102+
wmiError:= fmt.Errorf("%s failed:\n%s ", strings.Join(cmd.Args, " "), out)
103+
errorMessage := fmt.Errorf("%s\n%s", cimError, wmiError)
104+
fixMessage := "Start PowerShell as an Administrator"
105+
return registry.State{Installed: false, Running: true, Error: errorMessage, Fix: fixMessage, Doc: docURL}
106+
}
101107
}
102108

103109
// Get-Wmiobject does not return an error code for false

0 commit comments

Comments
 (0)