Skip to content
This repository has been archived by the owner on Sep 26, 2021. It is now read-only.
This repository has been archived by the owner on Sep 26, 2021. It is now read-only.

Pre-create check: "Hyper-V PowerShell Module is not available" #4424

Closed

Description

Please note: this is NOT a duplicate of #4342.

Running docker-for-windows 18.03.0.16511-edge.

Command:

PS C:\Users\pdadmin> docker-machine --debug create -d hyperv --hyperv-virtual-switch "ToInternal" DockerHostA
Docker Machine Version:  0.14.0, build 89b8332
Found binary path at C:\Program Files\Docker\Docker\Resources\bin\docker-machine.exe
Launching plugin server for driver hyperv
Plugin server listening at address 127.0.0.1:49951
() Calling .GetVersion
Using API Version  1
() Calling .SetConfigRaw
() Calling .GetMachineName
(flag-lookup) Calling .GetMachineName
(flag-lookup) Calling .DriverName
(flag-lookup) Calling .GetCreateFlags
Found binary path at C:\Program Files\Docker\Docker\Resources\bin\docker-machine.exe
Launching plugin server for driver hyperv
Plugin server listening at address 127.0.0.1:49955
() Calling .GetVersion
Using API Version  1
() Calling .SetConfigRaw
() Calling .GetMachineName
(DockerHostA) Calling .GetMachineName
(DockerHostA) Calling .DriverName
(DockerHostA) Calling .GetCreateFlags
(DockerHostA) Calling .SetConfigFromFlags
Reading certificate data from C:\Users\pdadmin\.docker\machine\certs\ca.pem
Decoding PEM data...
Parsing certificate...
Reading certificate data from C:\Users\pdadmin\.docker\machine\certs\cert.pem
Decoding PEM data...
Parsing certificate...
Running pre-create checks...
(DockerHostA) Calling .PreCreateCheck
(DockerHostA) DBG | [executing ==>] : C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -NonInteractive @(Get-Command hyper-v\Get-VM).ModuleName
(DockerHostA) DBG | [stdout =====>] : hyper-v
(DockerHostA) DBG |
(DockerHostA) DBG | [stderr =====>] :
Error with pre-create check: "Hyper-V PowerShell Module is not available"
notifying bugsnag: [Error with pre-create check: "Hyper-V PowerShell Module is not available"]

The issue is again with https://github.com/docker/machine/blob/master/drivers/hyperv/powershell.go with the hypervAvailable() function.

As you can see by the debug above, trying this in PowerShell...

& "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -NonInteractive "@(Get-Command hyper-v\Get-VM).ModuleName"

...gives you lowercase, i.e. 'hyper-v' and the Go code checks for uppercase 'Hyper-V'.

There are a few solutions.

BEST SOLUTION (in my opinion):

Generally, when determining if a particular PowerShell Module is installed/available, you would use the Get-Module cmdlet. So line 58 in https://github.com/docker/machine/blob/master/drivers/hyperv/powershell.go would go from...

stdout, err := cmdOut("@(Get-Command hyper-v\\Get-VM).ModuleName")

...to...

stdout, err := cmdOut("@(Get-Module -ListAvailable hyper-v).Name | Get-Unique")

SOLUTION 2:

Change line 58 from...

stdout, err := cmdOut("@(Get-Command hyper-v\\Get-VM).ModuleName")

...to...

stdout, err := cmdOut("@(Get-Command Hyper-V\\Get-VM).ModuleName")

SOLUTION 3:

Make line 64...

if resp[0] != "Hyper-V" {

...case insensitive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions