title: How do I properly pass arguments to a scriptblock using powershell runspaces?
body: <p>While using runspaces I would like to pass predictable arguments to my scriptblock from outside. In order to do this without utilizing <strong>$args</strong> (to avoid making the code less readable), I am storing my argument in a variable called <strong>$var</strong> and adding the variable to the InitialSessionState of the RunspacePool. To do this I am using the <code>Add</code> method of <code>System.Management.Automation.Runspaces.InitialSessionState.Create().Variables</code> </p>
  
  <p>This works for my purposes, but I also noticed the <code>PowerShell.AddParameter</code> method of <code>[PowerShell]::Create()</code>which would add my parameter to each powershell process as it is created.</p>
  
  <p>And finally there is the <code>PowerShell.AddArgument</code> which I could use like <code>AddParameter</code>, and use a <code>param()</code> block. this would work, however, each argument will be passed in order, and ends up working as well as <strong>$args</strong>.</p>
  
  <p>So my question is what is the recommended way of passing arguments\parameters\variables into a scriptblock for the purposes I have defined? Is there a performance advantage of one over the other? Can you expand on what purpose you may use one over the other?</p>