Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ImportPSModulesFromPath support #177

Open
beargle opened this issue Mar 6, 2018 · 5 comments · Fixed by MVKozlov/PoshRSJob#1
Open

Add ImportPSModulesFromPath support #177

beargle opened this issue Mar 6, 2018 · 5 comments · Fixed by MVKozlov/PoshRSJob#1

Comments

@beargle
Copy link

beargle commented Mar 6, 2018

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:

  • "Installed" and accessible in $env:PSModulePath
  • Passed by name to Start-RSJob using the -ModuleToImport parameter

What 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 on Install-Module or 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:PSModulePath

Start-RSJob -ModulesToImport @("Pester")...

Would like to be able to pass in a custom module path, from which one or more modules are imported. Assuming a directory structure of:

Dependencies/
    PowerShell/
        Modules/

We should be able to:

Start-RSJob -ModulesFromPathToImport ".\Dependencies\PowerShell\Modules"...
@beargle
Copy link
Author

beargle commented Mar 6, 2018

If this looks like something that would be useful, I'm happy to put together a PR for review. Thanks!

@proxb
Copy link
Owner

proxb commented Mar 6, 2018

@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.

@MVKozlov
Copy link
Contributor

MVKozlov commented Mar 6, 2018

btw this can be done thru -ModulesToImport parameter like Import-Module -Name.
If supplied path exists, that it is path to module, if not - just module name
and path can support wildcards thru Resolve-Path

@beargle
Copy link
Author

beargle commented Mar 7, 2018

@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 with Resolve-Path and wildcards.

I haven't been able to get -ModulesToImport to 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!

@MVKozlov
Copy link
Contributor

MVKozlov commented Mar 7, 2018

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 list to names and paths

MVKozlov added a commit to MVKozlov/PoshRSJob that referenced this issue May 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants