sous-chefs / powershell

Development repository for the powershell cookbook
https://supermarket.chef.io/cookbooks/powershell
Apache License 2.0
110 stars 88 forks source link

Name of module is not valid when installed with powershell_module #102

Closed russellseymour closed 7 years ago

russellseymour commented 7 years ago

Cookbook version

v0.6.1

Chef-client version

12.16.42

Platform Details

Windows 2012 R2 - Test Kitchen Vagrant

Scenario:

Install PsGet module using the powershell_module resource

Steps to Reproduce:

Use the example as described in the README, e.g.

powershell_module "posh-git" do
  package_name "posh-git"
  source "https://github.com/dahlbyk/posh-git/zipball/master"
end

Expected Result:

The module should be installed in C:\Program Files\WindowsPowerShell\Modules\posh-git so that Windows PowerShell will find it when the command Import-Module posh-git is run.

Actual Result:

If the above example is run then the module is installed to C:\Program Files\WindowsPowerShell\Modules\dahlbyk-posh-git-fba883f so the Import-Module posh-git does not work.

I thought that the package_name attribute would correctly set the directory, but this does not appear to be the case.

The situation is improved slightly if the URL for a released zip is used, so the following:

powershell_module "posh-git" do
  package_name "posh-git"
  source "https://github.com/dahlbyk/posh-git/releases/tag/v0.6.1"
end

Will put the module in C:\Program Files\WindowsPowerShell\Modules\posh-git-0.6.1 so additional code could be written to move this to posh-git. This is a necessary step as the folder name must match the name of the PowerShell Data File in the module .psd1 file, if not then it will not be imported.

There is a work around that will allow a module to be imported, e.g.

Import-Module "C:\Program Files\WindowsPowerShell\Modules\posh-git-0.6.1\posh-git.psd1"

But this breaks the auto importing that PowerShell can do when modules are in paths set in the $env:PSModulePath variable and is a pain to have to type.

jugatsu commented 7 years ago

@russellseymour you can use buil-in powershell_package provider for installing powershell modules.

stuartpreston commented 7 years ago

@russellseymour Closing this due to age and I think powershell_package is the way forward here.