Need a clean way to splat a hashtable against the various commands that take an ArgumentList - by Keith Hill MVP

Status : 

 


11
0
Sign in
to vote
ID 797536 Comments
Status Active Workarounds
Type Suggestion Repros 0
Opened 8/15/2013 5:12:38 PM
Access Restriction Public

Description

There are several commands that have an ArgumentList parameter that take arguments bound for a PowerShell command. However, this parameter doesn't support splatting in any sort of easy and/or obvious way.  
Sign in to post a comment.
Posted by Ieuan Jenkins on 3/18/2015 at 4:33 AM
The solution suggested by Microsoft in:
https://connect.microsoft.com/PowerShell/feedback/details/623344/commands-with-argumentlist-should-have-a-parameter-set-with-parameters-too

isn't a full alternative.

For example it doesn't help in the following situation because I can't make use of the $using: scope when I'm passing a function from the local session:
###
Function Do-Something
{
Param($one, $two, $three)

Return ($one + $two + $three)
}

$doParam = @{'One' = 1; 'Two' = 2; 'Three' = 3}
Invoke-Command -Computername 'Server01' -Scriptblock ${function:Do-Something} -ArgumentList ($doParam.One, $doParam.Two, $doParam.Three)
###
Posted by Derp McDerp on 12/21/2013 at 4:00 PM
This is kind of a duplicate of:

https://connect.microsoft.com/PowerShell/feedback/details/623344/commands-with-argumentlist-should-have-a-parameter-set-with-parameters-too

See my comment about Perl 6 Parcels for a solution to this problem.
Posted by Jeffery Hicks on 8/15/2013 at 5:47 PM
This is really needed. I ran into this trying to use Invoke-Command to run a script on my machine on a remote machine. It works if parameters are are positional, but then you have to enter all the values with -Argumentlist. This approach fails with named parameters and makes it very difficult to take advantage of default parameter values.
Posted by Keith Hill MVP on 8/15/2013 at 5:25 PM
OK the more I think about this, the more I don't like the -ArgumentList @arglist bit since splatting means apply to the current command (icm in the example above) and not the script being invoked. Hmm, guess the -SplatArguments switch parameter is sounding better to me.