Skip to content

-ImportVariables/-ImportModules/-ImportFunctions #52

Closed

Description

@God-damnit-all

RamblingCookieMonster once created something similar to this (though I don't think it was ever published to PowerShell Gallery); it's simply called Invoke-Parallel.

This function had three switches that simplified things considerably: -ImportVariables/-ImportModules/-ImportFunctions

Rather than defining each variable, module, or function you wanted one-at-a-time, it would import everything from the local session. While this really isn't an optimal approach, it's certainly a convenient one in some circumstances.

It'd be nice if PSParallelPipeline had these switches as well.

Activity

  1. santisq commented on Jul 24, 2026

    @santisq
    Owner

    @God-damnit-all I don't like the idea of keep adding more parameters to the cmdlet. What can be done is make it so -Variables can take strings with wildcards then something like this works:

    $foo, $bar, $baz = 1, 2, 3
    .... | Invoke-Parallel { $foo, $bar, $baz } -Variables *

    Same for -Functions *. For -ModuleNames I will not consider it as needed since modules are automatically imported in the parallel scope due to discovery as long as they're correctly installed in one of the $env:PSModulePath paths.

  2. God-damnit-all commented on Jul 24, 2026

    @God-damnit-all
    Author

    Sounds good!

  3. self-assigned this
    on Jul 27, 2026
  4. santisq commented on Jul 27, 2026

    @santisq
    Owner

    @God-damnit-all before this update, when -Functions was passed a non-existent name it'd throw:

    $"The function with name '{function}' could not be found."

    Which, after the update has now been changed to:

    $"Could not find any function matching the name or pattern '{function}'."

    Should it behave the same way for -Variables when passed a string that may or may not contain a wildcard? e.g.:

    $"Could not find any variable matching the name or pattern '{variable}'."

  5. God-damnit-all commented on Jul 28, 2026

    @God-damnit-all
    Author

    Should it behave the same way for -Variables when passed a string that may or may not contain a wildcard? e.g.:

    Technically you can have wildcard characters in both variables and functions too (and not just their aliases):

    function * { "foo" }
    *
    # Output: foo
    
    ${*} = "bar"
    ${*}
    # Output: bar

    But as long as it honors wildcard escapes, it shouldn't be an issue.

  6. God-damnit-all commented on Jul 28, 2026

    @God-damnit-all
    Author

    [I'm reposting this edit entirely just in case you rely on email alerts (because I changed my suggestion).]

    I suppose you could check if there's a literal match for the string before trying it as a wildcard, and if there's a literal match, continue with importing via wildcard, but issue a warning along with an instruction that if a user wants to suppress the warning, they can set $PSParallelPipelineNoLiteralWildcardWarning to $true (so you wouldn't have to add a switch just for this one edge-case).

  7. santisq commented on Jul 28, 2026

    @santisq
    Owner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

documentationImprovements or additions to documentationenhancementNew feature or request

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions