Tandem PowerShell Sessions

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.

Start-TandemServer

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.

Enter-TandemServer

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.

Here’s a video of it in action. To download the scripts grab this zip!

You can leave a response, or trackback from your own site.

3 Responses to “Tandem PowerShell Sessions”

  1. [...] Tandem PowerShell Sessions (Adam Driscoll) [...]

  2. Matt says:

    This is just awesome. From a support perspective it would be great to have a way to sit-in on someones PowerShell Session without using application-sharing over an IM application of sorts.

    • adamdriscoll says:

      Yeah, I think it would be awesome to see something like this fleshed out. I hope the article gets someones gears going. :) Thanks for the feedback!

Leave a Reply


+ two = 6

Subscribe to RSS Feed Follow me on Twitter!