I suggest changing the current behavior of Get-Module <path-to-directory> -ListAvaialble and Get-Module <path-to-directory> -ListAvaialble.
Today, Get-Module <path-to-directory> -ListAvaialble assumes the passed in directory is a module folder -- it uses the directory name as the module name and only tries to find valid module files with the same name right under the directory. Get-Module <path-to-directory> -ListAvaialble -All does recursively search the directory for valid module files, but then it filters the found modules using the directory name, so again, only the modules with the same name as the given directory name can be returned. Both behaviors seem wrong and useless to me.
I think for Get-Module <directory-Foo> -ListAvailable and Get-Module <directory-Foo> -ListAvailable -All, the behaviors should be the same as if running Get-Module -ListAvailable and Get-Module -ListAvailable -All when $env:PSModulePath = <directory-Foo>. Namely, Get-Module <directory-Foo> -ListAvailable should treat directory-Foo as a module path, and find all availalbe default modules within that module path; Get-Module <directory-Foo> -ListAvailable -All should also treat directory-Foo as a module path, and find all modules within that module path. The proposed behaviors make more sense because:
- The semantics of
-ListAvailable and -All is consistent between Get-Module <directory-path> and Get-Module <module-name>;
- The proposed behaviors are more useful since they allow the user to look for available modules from an arbitrary directory.
Expected Behavior
Get-Module "$PSHOME\Modules" -ListAvailable
## Return all availalbe default modules under '$PSHOME\Modules',
## just like running 'Get-Module -ListAvailable' when '$env:PSModulePath == "$PSHOME\Modules"'
Get-Module "$PSHOME\Modules" -ListAvailable -All
## Return all modules under '$PSHOME\Modules',
## just like running 'Get-Module -ListAvailable -All' when '$env:PSModulePath == "$PSHOME\Modules"'
Actual Behavior
PS:4> Get-Module "$PSHOME\Modules" -ListAvailable
Get-Module : The specified module 'C:\Program Files\PowerShell\6.0.2\Modules' was not found. Update the Name parameter to point to a valid path, and then try again.
At line:1 char:1
+ Get-Module "$PSHOME\Modules" -ListAvailable
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (C:\Program File...l\6.0.2\Modules:String) [Get-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFoundForGetModule,Microsoft.PowerShell.Commands.GetModuleCommand
PS:5> Get-Module "$PSHOME\Modules" -ListAvailable -All
Get-Module : The specified module 'C:\Program Files\PowerShell\6.0.2\Modules' was not found. Update the Name parameter to point to a valid path, and then try again.
At line:1 char:1
+ Get-Module "$PSHOME\Modules" -ListAvailable -All
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (C:\Program File...l\6.0.2\Modules:String) [Get-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFoundForGetModule,Microsoft.PowerShell.Commands.GetModuleCommand
I suggest changing the current behavior of
Get-Module <path-to-directory> -ListAvaialbleandGet-Module <path-to-directory> -ListAvaialble.Today,
Get-Module <path-to-directory> -ListAvaialbleassumes the passed in directory is a module folder -- it uses the directory name as the module name and only tries to find valid module files with the same name right under the directory.Get-Module <path-to-directory> -ListAvaialble -Alldoes recursively search the directory for valid module files, but then it filters the found modules using the directory name, so again, only the modules with the same name as the given directory name can be returned. Both behaviors seem wrong and useless to me.I think for
Get-Module <directory-Foo> -ListAvailableandGet-Module <directory-Foo> -ListAvailable -All, the behaviors should be the same as if runningGet-Module -ListAvailableandGet-Module -ListAvailable -Allwhen$env:PSModulePath = <directory-Foo>. Namely,Get-Module <directory-Foo> -ListAvailableshould treatdirectory-Fooas a module path, and find all availalbe default modules within that module path;Get-Module <directory-Foo> -ListAvailable -Allshould also treatdirectory-Fooas a module path, and find all modules within that module path. The proposed behaviors make more sense because:-ListAvailableand-Allis consistent betweenGet-Module <directory-path>andGet-Module <module-name>;Expected Behavior
Actual Behavior