title: Powershell Passing Parameters to Nested Start-Job
body: <p>I am attempting to pass paramters to a nested job.</p>
  
  <pre><code>$executepath = "D:\nttools\CoreAutomation\$patch.zipfilename\$ntupdatefilename"
  
  $sb = {Start-Job -Name $NTUpdate -ScriptBlock {&amp; cmd.exe /c $executepath}}
  
  Invoke-Command -Session $NTSession -ScriptBlock $sb -ArgumentList $executepath
  </code></pre>
  
  <p>With this output showing the command is not actually rendering the parameter in the string:</p>
  
  <pre><code>State          : Running
  PSComputerName : LKS.nt.isg.local
  RunspaceId     : 8a1c9cc2-1cd0-42a6-a1d0-89d977aabf04
  HasMoreData    : True
  StatusMessage  :
  Location       : localhost
  Command        : &amp; cmd.exe /c $executepath
  JobStateInfo   : Running
  InstanceId     : 9e95c0d8-d177-4a1a-9283-56f07ff5f0a8
  Id             : 1
  Name           : Job1
  ChildJobs      : {System.Management.Automation.PSRemotingChildJob}
  PSJobTypeName  : BackgroundJob
  PSBeginTime    : 5/9/2017 2:00:49 PM
  PSEndTime      :
  </code></pre>
  
  <p>I have tried to add this parameters in the script block as well with the same result:</p>
  
  <pre><code>$executepath = "D:\nttools\CoreAutomation\$patch.zipfilename\$ntupdatefilename"
  
  $sb = {Start-Job -Name $NTUpdate -ScriptBlock {param($executepath) &amp; cmd.exe /c $executepath} -ArgumentList $executepath}
  
  Invoke-Command -Session $NTSession -ScriptBlock $sb -ArgumentList $executepath
  
  
  State          : Running
  PSComputerName : LKS.nt.isg.local
  RunspaceId     : 7e039382-d8a6-4298-9983-8f3f6fd2a6c3
  HasMoreData    : True
  StatusMessage  :
  Location       : localhost
  Command        : param($executepath) &amp; cmd.exe /c $executepath
  JobStateInfo   : Running
  InstanceId     : 77e80c13-2801-4726-81f4-8c960319cd0b
  Id             : 1
  Name           : Job1
  ChildJobs      : {System.Management.Automation.PSRemotingChildJob}
  PSJobTypeName  : BackgroundJob
  PSBeginTime    : 5/9/2017 2:08:38 PM
  PSEndTime      :
  </code></pre>
  
  <p><strong>Updated:</strong></p>
  
  <p>Tried what was listed in comments. No luck, <strong>same result</strong>.</p>
  
  <pre><code>$executepath = "D:\nttools\CoreAutomation\$patch.zipfilename\$ntupdatefilename"
  
  $sb = {param($executepath) Start-Job -Name NTUpdate -ScriptBlock {param($executepath) &amp; cmd.exe /c $executepath} -ArgumentList $executepath}
  
  Invoke-Command -Session $NTSession -ScriptBlock  $sb -ArgumentList $executepath
  
  
  State          : Running
  PSComputerName : LKS.nt.isg.local
  RunspaceId     : 7b7b86df-a216-494e-b7e7-2336e6994a06
  HasMoreData    : True
  StatusMessage  :
  Location       : localhost
  Command        : param($executepath) &amp; cmd.exe /c $executepath
  JobStateInfo   : Running
  InstanceId     : 4d5dd307-2158-4b38-b118-987f1e56cb12
  Id             : 1
  Name           : NTUpdate
  ChildJobs      : {System.Management.Automation.PSRemotingChildJob}
  PSJobTypeName  : BackgroundJob
  PSBeginTime    : 5/9/2017 2:25:19 PM
  PSEndTime      :
  </code></pre>
  
  <p><strong>Update 2 -$using:executepath</strong></p>
  
  <pre><code>Invoke-Command -Session $NTSession -ScriptBlock {Start-Job -Name NTUpdate -ScriptBlock {&amp; cmd.exe /c $Using:executepath}}
  </code></pre>
  
  <p>I have tried with and I get this error:</p>
  
  <pre><code>The value of the using variable '$using:executepath' cannot be retrieved because it has not been set in the local
  session.
      + CategoryInfo          : InvalidOperation: (:) [Start-Job], RuntimeException
      + FullyQualifiedErrorId : UsingVariableIsUndefined,Microsoft.PowerShell.Commands.StartJobCommand
      + PSComputerName        : LKSNTADM01.nt.isg.local
  </code></pre>