The only thing I can think of which meets the requirements you've listed would be to create a new instance of System.Management.Automation.PowerShell and run the scripts inside that. Then you can set up event handlers to respond to the various streams as they write data, and push them into a queue to be added to SQL (which should preserve their order, since PowerShell is basically single-threaded.) In order to do this properly without screwing up the order, you'd probably have to implement parts of it in C# using a .NET event handler directly, instead of writing it in PowerShell and using Register-ObjectEvent.
↧