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

Support splatting -ArgumentList with hashtable too #37

Open
o-l-a-v opened this issue May 27, 2024 · 0 comments
Open

Support splatting -ArgumentList with hashtable too #37

o-l-a-v opened this issue May 27, 2024 · 0 comments

Comments

@o-l-a-v
Copy link

o-l-a-v commented May 27, 2024

Summary of the new feature / enhancement

Start-ThreadJob (and Start-Job for reference) currently only supports splatting -ArgumentList with array:

This means some example code must be like this:

$JobsUsingArray  = [array](
    1 .. 3 | ForEach-Object -Process {
        Start-ThreadJob -ScriptBlock {
            [OutputType([System.String])]
            Param(
                [Parameter(Mandatory,Position=0)][string]$SomeParameter
            )
            Write-Output -InputObject $SomeParameter
        } -ArgumentList ('Hello {0}' -f $_)
    }
)
Receive-Job -Job $JobsUsingArray -Wait

which returns:

Hello 1
Hello 2
Hello 3

I much prefer to splat using name of the input parameters, so splatting with hashtable. I'd like this to work too:

$JobsUsingHashtable = [array](
    1 .. 3 | ForEach-Object -Process {
        Start-ThreadJob -ScriptBlock {
            [OutputType([System.String])]
            Param(
                [Parameter(Mandatory)][string]$SomeParameter
            )
            Write-Output -InputObject $SomeParameter
        } -ArgumentList @{
            'SomeParameter' = [string] 'Hello {0}' -f $_
        }
    }
)
Receive-Job -Job $JobsUsingHashtable -Wait

which returns

System.Collections.Hashtable
System.Collections.Hashtable
System.Collections.Hashtable

Proposed technical implementation details (optional)

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant