You're specifying the script both in CreatePipeline(scriptText)
and AddScript(scriptText)
.
I'm not a Powershell user, but I'd suggest that either you want
using (Pipeline pipeline = runspace.CreatePipeline())
{
pipeline.Commands.AddScript(scriptText);
...
}
... or you want to remove the AddScript
call entirely. If there's a particular reason you need AddScript
, then creating the pipeline without the scriptText
seems the logical approach.