From d9c07c707932cbc92fb647cfd2387dae6d788835 Mon Sep 17 00:00:00 2001 From: Nikhil Sharma Date: Sat, 12 Feb 2022 14:00:50 +0530 Subject: [PATCH] Added Get-CimInstance with deprecated Get-Wmiobject to detect Hyper-V availability --- pkg/minikube/registry/drvs/hyperv/hyperv.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pkg/minikube/registry/drvs/hyperv/hyperv.go b/pkg/minikube/registry/drvs/hyperv/hyperv.go index f711c6c92bb5..e80710df4c10 100644 --- a/pkg/minikube/registry/drvs/hyperv/hyperv.go +++ b/pkg/minikube/registry/drvs/hyperv/hyperv.go @@ -91,13 +91,19 @@ func status() registry.State { ctx, cancel := context.WithTimeout(context.Background(), 8*time.Second) defer cancel() - cmd := exec.CommandContext(ctx, path, "-NoProfile", "-NonInteractive", "@(Get-Wmiobject Win32_ComputerSystem).HypervisorPresent") + cmd := exec.CommandContext(ctx, path, "-NoProfile", "-NonInteractive", "@(Get-CimInstance Win32_ComputerSystem).HypervisorPresent") out, err := cmd.CombinedOutput() if err != nil { - errorMessage := fmt.Errorf("%s failed:\n%s", strings.Join(cmd.Args, " "), out) - fixMessage := "Start PowerShell as an Administrator" - return registry.State{Installed: false, Running: true, Error: errorMessage, Fix: fixMessage, Doc: docURL} + cimError := fmt.Errorf("%s failed:\n%s ", strings.Join(cmd.Args, " "), out) + cmd := exec.CommandContext(ctx, path, "-NoProfile", "-NonInteractive", "@(Get-Wmiobject Win32_ComputerSystem).HypervisorPresent") + out, err := cmd.CombinedOutput() + if err != nil { + wmiError:= fmt.Errorf("%s failed:\n%s ", strings.Join(cmd.Args, " "), out) + errorMessage := fmt.Errorf("%s\n%s", cimError, wmiError) + fixMessage := "Start PowerShell as an Administrator" + return registry.State{Installed: false, Running: true, Error: errorMessage, Fix: fixMessage, Doc: docURL} + } } // Get-Wmiobject does not return an error code for false