Skip to content

Unix implementation does not use PSModule env variable #2677

Closed

Description

I have read the known issues, faq and searched for open issues matching this, and I found nothing, so hoping this is new to you. I tried splitting up a script into modules, and found that I need to add the current path to PSModulePath in order to do so. Whatever I did, Powershell never found the module. After doing the same in Windows, I discovered it perfectly there immediately. I can see no issues regarding casing here, so that tip does not seem to apply here.

Steps to reproduce

First, download latest version 6 alpha build (12 as of now) for Mac. Then clone and run the test case:

git clone https://github.com/fatso83/powershell-module-test
cd powershell-module-test
powershell -File bar-test.ps1

Expected behavior

This should be output (which is the case on Windows, using Powershell 3):

Oh, hello there. You are now loading the Bar module  

Bar says hello

Actual behavior

Import-Module : The specified module 'Bar' was not loaded because no valid module file was found in any module directory.
At /Users/carl-erik.kopseng/powershell-module-test/bar-test.ps1:9 char:1
+ Import-Module Bar
+ ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (Bar:String) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

BarHello : The term 'BarHello' 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 /Users/carl-erik.kopseng/powershell-module-test/bar-test.ps1:12 char:8
+ $res = BarHello
+        ~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (BarHello:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.0.0-alpha
PSEdition                      Core
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   3.0.0.0
GitCommitId                    v6.0.0-alpha.12
CLRVersion
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Activity

  1. added
    WG-Engine
    on Nov 14, 2016
  2. iSazonov commented on Nov 15, 2016

    @iSazonov
    Collaborator

    Perhaps this is related to # 2679.

  3. fatso83 commented on Nov 16, 2016

    @fatso83
    Author

    Ilya (@iSazonov), I don't think this is related to #2679, as I am not running Docker. This a standard OS X install, and I have a root mount point:

    $ df
    Filesystem                              512-blocks      Used        Available Capacity iused      ifree %iused  Mounted on
    /dev/disk1                               974700800 424139040        550049760    44% 3226299 4291740980    0%   /
    devfs                                          483       483                0   100%     837          0  100%   /dev
    map -hosts                                       0         0                0   100%       0          0  100%   /net
    map auto_home                                    0         0                0   100%       0          0  100%   /home
    map -fstab                                       0         0                0   100%       0          0  100%   /Network/Servers
    localhost:/93MKoOWlwe2pb4mzjBi4qH        974700800 974700800                0   100%       0          0  100%   /Volumes/MobileBackups
    /dev/disk2s2                            1952786352 883099880       1069686472    46% 6903225 4288064054    0%   /Volumes/Carl-Eriks backup
    kbfs@kbfuse0                      4503599627370488         0 4503599627370488     0%       0          0  100%   /keybase
    
  4. JamesWTruher commented on Nov 17, 2016

    @JamesWTruher
    Collaborator

    PSMODULEPATH is case sensitive on non-Windows systems. Could you set $env:PSMODULEPATH (cased as provided) to your desired path and try again?

  5. fatso83 commented on Nov 18, 2016

    @fatso83
    Author

    James Truher (@JamesWTruher), that was it!

    $ powershell -File bar-test.ps1
    Oh, hello there. You are now loading the Bar module
    
    Bar says hello
    
    
    carl-erik.kopseng at MWNOOSLMACLT280 in ~/dev-priv/powershell-module-test (master)
    $ git diff
    diff --git a/bar-test.ps1 b/bar-test.ps1
    index 60498ad..0dd8281 100644
    --- a/bar-test.ps1
    +++ b/bar-test.ps1
    @@ -1,6 +1,6 @@
     # set the path as the path for loading modules
     # (I don't concatenate the existing path here to avoid x-platform differences complications)
    -$env:PSModulePath = $PSScriptRoot
    +$env:PSMODULEPATH = $PSScriptRoot
    
     Import-Module Bar

    I did get the casing from official microsoft articles so it's too bad that those paths differ in casing, but glad to see that it works now! Thanks!

  6. added
    Resolution-By Design
    on Nov 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution-By DesignWG-Engine

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions