While using runspaces I would like to pass predictable arguments to my scriptblock from outside. In order to do this without utilizing $args (to avoid making the code less readable), I am storing my argument in a variable called $var and adding the variable to the InitialSessionState of the RunspacePool. To do this I am using the Add method of System.Management.Automation.Runspaces.InitialSessionState.Create().Variables
This works for my purposes, but I also noticed the PowerShell.AddParameter method of [PowerShell]::Create()which would add my parameter to each powershell process as it is created.
And finally there is the PowerShell.AddArgument which I could use like AddParameter, and use a param() block. this would work, however, each argument will be passed in order, and ends up working as well as $args.
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?