Repository navigation
Add ImportPSModulesFromPath support #177
Description
Activity
If this looks like something that would be useful, I'm happy to put together a PR for review. Thanks!
@beargle This sounds cool! I am definitely done with adding new features for V2 and have already moved the V2 supporting module onto its own branch. I just need to work on removing the V2 code as well as adding a warning when this module is imported from a V2 host. I should have that completed by the end of the week if you can wait until then, otherwise go ahead and do the PR and I will merge it and then begin work on removing the V2 stuff.
btw this can be done thru
-ModulesToImportparameter likeImport-Module -Name.
If supplied path exists, that it is path to module, if not - just module name
and path can support wildcards thruResolve-PathReacted by Boe Prox@MVKozlov Good point about similar functionality with
-ModulesToImport; I do see that it could be used if the collection of module paths is pre-built withResolve-Pathand wildcards.I haven't been able to get
-ModulesToImportto work with a single path that contains module subdirectories (ex. like what Windows users have at~\Documents\WindowsPowerShell\Modules). Am I missing something on that front?Regardless, PR has been raised - would appreciate any feedback you all have. Thanks!
I this this way close to your needs
$list = 'PoshWSUS', 'D:\Work\ps\test\', 'D:\Work\ps\test\PSAlphaFS\2.0.0.1\*.psm1' $modulenames = New-Object System.Collections.ArrayList $modulepaths = $list | ForEach-Object { $m = $_ try { Resolve-Path $_ -ErrorAction Stop | Select-Object -ExpandProperty Path } catch { $null = $modulenames.Add($m) } } $modulenames $modulepaths
here I'm split common
listtonamesandpaths- added a commit that references this issue
on May 28, 2019
Do you want to request a feature or report a bug?
Feature
What is the current behavior?
Importing modules in background runspace jobs requires that the module be:
$env:PSModulePathStart-RSJobusing the-ModuleToImportparameterWhat is the proposed behavior?
Add support for passing a custom module path, from which modules will be imported into background runspace jobs.
This should require no modification of
$env:PSModulePath, and shouldn't require the module to be pre-installed on the client. Expecting something similar to how modules are specified for import in psake-config.ps1. Specific use case is a portable CI/CD pipeline that manages PowerShell module dependencies, without relying onInstall-Moduleor a specific build server configuration.It looks like InitialSessionState.ImportPSModulesFromPath() could work for this, but would make a hard dependency on PowerShell V3. Wasn't sure if PowerShell V2 support was still important based on #162.
Please provide a code example showing the potential feature, if applicable:
Today we pass in one or more module names to import, which have to be accessible with
$env:PSModulePathWould like to be able to pass in a custom module path, from which one or more modules are imported. Assuming a directory structure of:
We should be able to: