I'm scratching my head trying to figure out why parameter splatting won't work for a set of workflow runbooks executed in Azure Automation.
I've got 3 runbooks (super, sub, child) that are called in a nested fashion. They all share (generally) the same parameters. In my real-world scenario, I have multiple sub & child runbooks and I want to use splatting so I could define a hashtable once and pass it as needed, without having to list out all the params.
I've also tried using the -PSParameterCollection
parameter. However, in Azure Automation, this appears only to be available for the topmost runbook (which already works), as it throws a parameter not found error for it in the children. The Note section here says Workflows that are nested three levels deep do not support any common parameters, including workflow common parameters, which seems like it could be a problem, depending on how these runbooks are compiled.. but I don't think I can avoid that without limiting the reusability of the runbooks. I wouldn't expect called workflows to be compiled as nested workflows within the calling one.
The error I get is:
$newnumber = sub @splatter
~~~~~~~~~~
Could not find a parameter named '0'. Supported parameters are: Debug, ErrorAction, ....
Oddly enough, unlike what I'm seeing with these test runbooks, in my 'real-world' workflows, I don't get this error in the top-level runbook - only when calling the 'child' runbooks from within 'sub'.
workflow child
{
Param ([int]$val)
Write-Verbose "child: val ($val)"
$NewNumber = $val*2
$NewNumber
}
workflow childtwo
{
Param ([int]$val, [int]$valtwo)
Write-Verbose "childtwo: val ($val) valtwo ($valtwo)"
$NewNumber = $val * $valtwo
$NewNumber
}
workflow sub
{
Param ([int]$val)
Write-Verbose "sub: val ($val)"
$splatter = @{ val = $val }
# works
$NewNumber = child -val $splatter.val
# fail
$NewNumber = child @splatter
# works
$NewNumber = childtwo -val $splatter.val -valtwo 2
# fail
$NewNumber = childtwo ($splatter + @{ valtwo = 2 })
$mergeSplatter = ($splatter + @{ valtwo = 2 })
$NewNumber = childtwo @mergeSplatter
$twoSplatter = @{ val = $val; valtwo = 2 }
$NewNumber = childtwo @twoSplatter
$NewNumber
}
workflow super
{
Param([int]$val)
Write-Verbose "super: id is $val"
$splatter = @{ val = $val }
$newnumber = sub -val $val
$newnumber = sub @splatter # @ or $ doesn't matter - fails the same
Write-Verbose "super: newnumber is $newnumber"
$newnumber
}
super 2
Please see https://technet.microsoft.com/en-us/library/jj574140.aspx?f=255&MSPPError=-21472173969:
You will need to either not use splatting or switch the PowerShell Workflow runbook to a native PowerShell runbook.