I am trying to use Start-Job to launch a new Powershell script. The new script has several parameters (some optional, some not), so I want to make a hashtable and splat them. However, one of these parameters is itself a hash table. I am trying to start the job like this:
$MyStringParam = "string1"
$MyHashParam = @{}
$MyHashParam.Add("Key1", "hashvalue1")
$arguments = @{MyStringParam=$MyStringParam;MyHashParam=$MyHashParam}
Start-Job -Name "MyJob" -ScriptBlock ([scriptblock]::create("C:\myscript.ps1 $(&{$args} @arguments)"))
Whereupon I get this error in the new job:
Cannot process argument transformation on parameter 'arguments'.
Cannot convert the "System.Collections.Hashtable" value of
type "System.String" to type "System.Collections.Hashtable".
Looks like it's treating the value I want to pass in as a hash table as a string. For the life of me I can't figure out how to get around this. Can anyone help?