In PowerShell you can pass multiple parameters to a function or cmdlet by wrapping them in a hashtable variable, then passing that variable prefixed with @
instead of $
.
Is it possible to splat with a hashtable which is a property of another object (i.e. as a one liner)? e.g. below I first have to assign the property (testInt
, testString
) to another variable before I can splat it to Demo
. I'd like some way to avoid this additional step, but haven't been able to find a neat solution...
function Demo {
[CmdletBinding()]
Param (
[Parameter()]
[string]$One
,
[Parameter()]
[string]$Two
)
"1 = $One"
"2 = $Two"
}
$test = @{
testInt = @{
One = '1'
Two = '2'
}
testString = @{
One = 'One'
Two = 'Two'
}
}
$t = $test.testInt
Demo @t
$t = $test.testString
Demo @t
Demo @test.testInt #this doesn't work / I've also tried similar options with various castings and braces though to no avail.
Update
Suggestion submitted: https://github.com/PowerShell/PowerShell/issues/5227