Power Remote Shell : Deploy Scripts to Multiple Machines

Morpheus

Yes it is true, you never have to write that wrapper again. Because, Power Remote Shell will take care of it in the background.

If you are working in a corporate environment and a major part of every script you write would be to loop through multiple remote machines, execute a piece of code on them simultaneusly and track the results as well, let me make your life a little more easier. Introducing, The Power Remote Shell.

I agree, the name is a little ambiguous. I did ponder a while what to name this simple yet elegant app. After going through 4 different names that triggered numerous water cooler debates, I figured I am going to call it The Power Remote Shell. [Github Download]

PowerRemoteShell

Oh where are my manners! Let me explain. Whatever you write in that little scriptblock box, will be executed locally on all the hosts you have added on the left side, simultaneously. Thats it, no confetti guns or fireworks. I guess now the name makes more sense. Just imagine the possibilities of what you can do with the app.

a. Want to install a software on 2000 remote machines? [Figure out how to do it on 1 machine using commandline or silent install options and put it in the scriptblock: &”Setup.exe /Install /Quiet /log C:\temp\installerlog.txt”]

b. Want to find the version of an installed App? [Put this in the scriptblock: Get-WmiObject -class win32_Product | Where-object -property Name -match “Wireshark” | Select Name, Version]

You can do with this app everything you can do on a local powershell console with the exception of interactive commands like “Read-host”, “Get-Credential” etc.

The Why and How

So, almost everyday, I found myself writing the same old monotonous wrapper to execute a simple set of PowerShell queries on a bunch of different servers, processing its results and so on. It gets harder when you want to do them all at once because you don’t have all day to wait on a screen. Doing them at once adds the additional complexity of adding code to track the different threads or processes. As painful as this is, not all admins like to script or much less understand them. They end up only caring about inputs and outputs and ignore the complexity involved.

The simplest form of multithreading in powershell is to use Background Jobs. I have been using them for very long and have always found them to be terribly inefficient and merciless with resource usage. If you have more than 50 machines in your list, you end up wishing you had ran it one after the other. So I sat and learned Runspaces. It is a little more harder to understand because it doesnt always make sense. But trust me, they are the fastest.

I was not a fan of Invoke-Command because it has an inherent dependency on WinRM which were not enabled by default on Windows 2008 variants. So using it in my code would essentially make it unreliable and to a spectator, I would be classiffied as a bad programmer through no fault of my own. And to be perfectly candid, it is not all that easy to move every piece of OS to the newer version unless you are on cloud. Anyway, I do not have the luxury to contemplate “what could have been”. I have to make do with what I got. Essentially, even before MS came up with Invoke-Command, the windows community was in love with Mark Russinovich’s PSTools, specifically, PSExec.exe. But it can be a little troublesome to deal with and slower in comparison. I figured, I could make a tool that utilizes both of their abilities and let them make up for each other’s flaws. And that is what you have here.

Why Power Remote Shell?

One word, Simplicity. All you have to do is add the remote hosts on the left panel, put the powershell or native cmd code on the scriptblock and hit Execute.

The application will loop through your remote host list, run the query in a multithreaded fashion, track and display the results on the bottom blue panel. Click on each machine to see it’s corresponding results.

PowerShell is a powerful language. It seldom gets its recognition because most people have not heard about it as the intended user community is limited. I think this tool wields great power in it’s ability to transform that power and put it in the hands of those who may not understand it. I just hope they remember:

homemaranhatioben_1-750x380

Development

While the app is fairly experimental, the essential functionalities work including the use of alternate credentials. I will continue to work on it when necessity calls.

Do let me know how the app worked for you. If you ran into any issues or how you wished it could be better and I will do my best to live up to your expectations.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s