❔ C# Powershell, pipe one script to another?

Is it possible to run a script and pipe that result to another?

The closest I find is something like this:

               System.Management.Automation.PSDataCollection<System.Management.Automation.PSObject> res = null;
               foreach (var item in this.tasks)
                {
                    Console.WriteLine($"Executing script: {scripts[item.script].path}");
                    // add current script and parameters
                    ps.AddScript(scripts[item.script].script, true).AddParameters(item.parameters);
                    // check if we got a previous result
                    if (res is not null)
                    {
                        // check if the result has anything in it
                        if (res.Count > 0)
                        {
                            // add the previous result as an argument for the current script
                            // this seems to add the result to the first parameter of the same type
                            ps.AddArgument(res[0]);
                        }
                    }

                    // Execute script
                    res = await ps.InvokeAsync();
                }
Was this page helpful?