OneGet / MicrosoftDockerProvider

Provider to search, save and install Docker
Other
133 stars 55 forks source link

Install-package docker fails : 'Get-WindowsFeature' is not recognized #26

Open erichexter opened 7 years ago

erichexter commented 7 years ago

cc/ @jayshah-msft @taylorb-microsoft @friism

Repro steps:

I am getting an exception on this line: https://github.com/OneGet/MicrosoftDockerProvider/blob/developer/DockerMsftProvider.psm1#L586

  1. create a new vm, install windows 2016 standard with Desktop experience, run windows update.
  2. add-windowsfeature containers
  3. reboot
  4. Install-Module -Name DockerMsftProvider -Repository PSGallery -Force
  5. Install-Package -Name docker -ProviderName DockerMsftProvider

Expected Result: Docker and Docker Engine are install on server

Actual Result: PS C:> Install-Package -Name docker -ProviderName DockerMsftProvider -Force Install-Package : The term 'Get-WindowsFeature' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1

erichexter commented 7 years ago

Whats strange is if I execute an install-module ServerManager I still get this error.

thecloudtaylor commented 7 years ago

@enderb-ms you where looking into to something similar correct?

erichexter commented 7 years ago

I created some additional Data Center and Standard VMs and I was not able to repro this. Its only happening on one Standard Edition VM.

erichexter commented 7 years ago

cc/ @enderb-ms @taylorb-microsoft

I found the issue. I don't understand exactly what is happening by one get but under the hood this is what I believe is happening.

The Install-package command invokes a new runspace or powershell instance, in the instance only the default modules are loaded. Inside this package there is a call to Get-WindowsFeature. When this is called, powershell attempts to resolve the method. To do this is searches the $env:PSModulePath for modules that contain this method. Apparently it does not search all of the paths in this environment variables, it only searches some of them. I had a user environment variable, which boxstarter created , I deleted that. Then I put the path that contains the ServerManager modules (the module which contains get-windowsfeature) to the front of this environment variable.
i.e. C:\Windows\system32\WindowsPowerShell\v1.0\Modules

After that, I started a new powershell session and then the package was able to install correctly.

dermeister0 commented 7 years ago

I have only default module paths, it's clean Windows Server 2016.

PS C:\Users\Administrator> $env:PSModulePath
C:\Users\Administrator\Documents\WindowsPowerShell\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules

I copied C:\Windows\System32\WindowsPowerShell\v1.0\Modules\ServerManager to C:\Users\Administrator\Documents\WindowsPowerShell\Modules as a work-around.

dermeister0 commented 7 years ago

It does not work in 32-bit PowerShell. It's some strange file system virtualization.

PS C:\Users\Administrator> [System.IntPtr]::Size
8
PS C:\Users\Administrator> $env:PSModulePath
C:\Users\Administrator\Documents\WindowsPowerShell\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system3
2\WindowsPowerShell\v1.0\Modules
PS C:\Users\Administrator> Import-Module ServerManager
PS C:\Users\Administrator> (gci 'C:\Windows\System32\WindowsPowerShell\v1.0\Modules').Length
78
PS C:\Users\Administrator> [System.IntPtr]::Size
4
PS C:\Users\Administrator> $env:PSModulePath
C:\Program Files\WindowsPowerShell\Modules;C:\Users\Administrator\Documents\WindowsPowerShell\Modules;C:\Program Files (
x86)\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules
PS C:\Users\Administrator> Import-Module ServerManager
Import-Module : The specified module 'ServerManager' was not loaded because no valid module file was found in any
module directory.
At line:1 char:1
+ Import-Module ServerManager
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (ServerManager:String) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

PS C:\Users\Administrator> (gci 'C:\Windows\System32\WindowsPowerShell\v1.0\Modules').Length
56
divya1231 commented 7 years ago

I was using powershell x86 when i got this error. Switching to Powershell , resolved the problem

friism commented 7 years ago

The script should check for whether it's in a 32bit console then

friism commented 7 years ago

cc @johnstep in case you end up fiddling with the provider

romulomadu-zz commented 6 years ago

Hi, I'm having the same problem:

Install-WindowsFeature : The term 'Install-WindowsFeature' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct
and try again.
At line:1 char:9
+ $null = Install-WindowsFeature containers
+         ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Install-WindowsFeature:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

But, if I followed right what @erichexter it not worked for me.

Someone knows an alternative? There is a way to install it manually?

MirzaSikander commented 6 years ago

Getting this on Windows Enterprise host.

NickiSibbern commented 6 years ago

Getting this on a windows server 2016 LTS NT 10.0.14393 Powershell 5.1

had to add C:\Windows\system32\WindowsPowerShell\v1.0\Modules to my PsModulePath as suggested by @erichexter which solved the issue.

wolffberg commented 6 years ago

Check if another module or function is overwriting the default Get-WindowsFeature. In our case we had Carbon (http://get-carbon.org) installed which took precedence over the default cmdlet.

anarsen commented 6 years ago

I'm using the DockerProvider through DSC, and figured I'd just set the PSModulePath env variable through DSC as well.

Works like a charm.