I would like to know how to have one PowerShell instance dynamically control another PowerShell instance:
- Open a PowerShell instance (ogPS .. going forward) and execute a PowerShell script
- From in the ogPS script, start another PowerShell instance (newPS .. going forward)
- Monitor in ogPS the StdOut & ErrOut of the newPS, allowing ogPS to "watch" the status of commands
- Drive newPS by sending/streaming new commands to the StdIn of newPS, by responding to when newPS has returned a prompt
- Control newPS by perhaps "breaking" an operation that is taking too long to respond
- ogPS should be able to drive the newPS to gracefully exit by sending
exit
to newPS's StdIn
... ideally this would all be async / event driven (but I'll take a polling solution too).
This answer https://stackoverflow.com/a/9620390/1327508 to a similar question seems to be able to open a new instance and statically run some command(s); but it's not what I'm looking for.
Similarly, this answer https://stackoverflow.com/a/52807020/1327508 opens newPS from ogPS, but that's only a small part of the overall question.
Thanks in advance!