title: Calling additional scripts as jobs
body: <p>I have a master script that is attempting to execute additional scripts against a list of servers it pulls from a table. I would like these additional scripts to be called asynchronously.</p>
  
  <p>These additional scripts require a number of parameters that I cannot for the life of me get passed from the main script.</p>
  
  <p>The child scripts all use the following parameters:</p>
  
  <pre><code>param(
  [string]$sqlsrv=$null,
  [string]$db=$null,
  [string]$server=$null,
  [string]$instance=$null
  )
  </code></pre>
  
  <p>These values are generated by the master script. I can easily call anyone of the child scripts from the command line like so:</p>
  
  <p>.\serverstatus.ps1 test test1 test2 test3
  Where test,test1,test2,test3 are the parameter values. </p>
  
  <p>The only way I am aware of to call these child scripts asynchronously is using Start-Job. I cannot get Start-Job to accept my parameters. This seems to get me close:</p>
  
  <pre><code>Start-Job serverstatus.ps1 $sqlsrv $db $server $instance
  </code></pre>
  
  <p>I get this error:</p>
  
  <pre><code>`Start-Job : Cannot bind parameter 'InitializationScript'.
  Cannot convert the "TESTSERVER" value of type "System.String" to type System.Management.Automation.ScriptBlock".
      At C:\SQLPS\ServerList.ps1:69 char:12
          + Start-Job &lt;&lt;&lt;&lt;  serverstatus.ps1 $sqlsrv $db $server $instance
          + CategoryInfo          : InvalidArgument: (:) [Start-Job], ParameterBindingException
          + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.StartJobCommand`
  </code></pre>
  
  <p>I have tried many methods of passing these parameters based on information found online. I just can't seem to make any progress. Any guidance is greatly appreciated.</p>
  
  <p><em><strong></em>*EDIT*</strong></p>
  
  <p>Ok using your example, I am attempting to do the same. here are my results. The output of Receive-Job is what is killing me. I can't seem to get anything meaningful from it.</p>
  
  <p><strong>ProcessServers.ps1</strong></p>
  
  <pre><code>{Gathers a list of servers and instances}
  Start-Job -FilePath .\serverstatus.ps1 -ArgumentList $sqlsrv,$destdb,$server,$instance
  </code></pre>
  
  <p>If I just write-output on the Start-Job line, all variables are properly populated as expected. Output looks like so:</p>
  
  <pre><code>Start-Job -FilePath .\GetServerDetails.ps1 -ArgumentList RADC00,ServerHistory,RADCHR01,RADCHR01
  </code></pre>
  
  <p>For testing purposes, I have modified GetServerDetails.ps1 to simply output the passed parameters. It looks as so:</p>
  
  <p><strong>GetServerDetails.ps1</strong></p>
  
  <pre><code>param($sqlsrv,$db,$server,$instance)
  "Parameters are: $sqlsrv, $destdb, $server, $instance"
  </code></pre>
  
  <p>So from the command line I run:</p>
  
  <pre><code>Start-Job -FilePath .\GetServerDetails.ps1 -ArgumentList RADC00,ServerHistory,RADCHR01,RADCHR01
  </code></pre>
  
  <p>Instead of output like you get, I get this:</p>
  
  <pre><code>PS C:\SQLPS&gt; Start-Job -FilePath .\GetServerDetails.ps1 -ArgumentList RADC00,ServerHistory,RADCHR01,RADCHR01
  
  Id              Name            State      HasMoreData     Location             Command
  --              ----            -----      -----------     --------             -------
  37              Job37           Running    True            localhost            param($sqlsrv,$destdb,...
  
  PS C:\SQLPS&gt; Receive-Job -id 37
  PS C:\SQLPS&gt;
  </code></pre>