1

I need to run two powershell commands one after the other, should I create a pipeline twice or is there a better option? Thanks

Runspace myRunSpace = RunspaceFactory.CreateRunspace(rc);
            myRunSpace.Open();

            Pipeline pipeLine = myRunSpace.CreatePipeline();

            using (pipeLine)
            {
                Command myCommand = new Command("Get-Command...");
            }

            Pipeline pipeLine2 = myRunSpace.CreatePipeline();

            using (pipeLine2)
            {
                Command myCommand = new Command("Get-Command...");
            }

2 Answers 2

1

A pipeline is, according to msdn, like an "assembly line", so if the results of the first command have nothing to do with the second command, you do not need a Pipeline, you can use a ScriptBlock instead, and invoke it with a RunspaceInvoke object.

See an example here.

Sign up to request clarification or add additional context in comments.

Comments

0

Would you be happier with your code if you wrote:

using (Pipeline pipeLine = myRunSpace.CreatePipeline())
{
    Command myCommand = new Command("Get-Command...");
}

?

1 Comment

Would this make any difference? Thanks

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.