This is more of a concept than an actual implementation. I usually like to have something working before blogging about it but summer time is making it hard to get things done! A couple of my co-workers are windbg gurus. One day they were working on something and it just blew my mind! They were both debugging an issue. One windbg session was acting as the server while another was acting as the client. Not only was it a great way to get another set of eyes on an issue but I thought it to be a great learning tool.
You probably know where I’m headed: this would be great in PowerShell!
I frequently have people IMing questions to me and it would be really awesome to just remote into their PowerShell session, see what is going on and even issue commands. Now, right off the top of my head I think that with some magic from Microsoft remoting would be repurposed to accomplish something like this (maybe I’m way off) but I made a simple TCP client and server script to accomplish the same thing. It only allows for issuing commands but it is kind of snazzy none the less.
Creates a new thread with a TCPListener running in it. When messages are received they are processed by the same runspace that the server PowerShell console is running in. To accomplish this I used a little C# magic. It enabled me to pass the runspace from one thread to another.
Connects to a tandem server using a TCPClient class. Any input is forwarded over to the tandem server and run in that runspace. What I still need to get working is seeing the output of the command on this side.