Saturday, September 23, 2006

Today I have played a bit with Microsoft's new command line tool called Windows PowerShell. Other names I have heard over the years include Microsoft Shell. The code name for the project was Monad. As usual, Microsoft cannot make it's mind and so, expect a lot of confusion. As a simple example: what would you expect the abbreviation for Windows PowerShell would be? WPS or PS maybe? But what when you install the tool, it has an icon like this: . If you look closely you will see the "MSH"...

Putting the naming inconsistency aside, I have decided to give it a try. It took few seconds to start for the first time, and I was presented with a message asking me if I want to run a software from untrusted publisher, which happens to be non other than Micorsoft Corporation:

Since this is one of my favourite companies, I just had to agree :-). It wasn't enough to agree just once ("[R] Run Once") because I was asked the same thing for a couple of times, so I have decided to trust MS always. Few seconds later, I had a command prompt ready.

The first impression is that it is very slow. The auto-completion function is slow, moving between directories is slow. But by slow I do not mean few seconds. I just mean it is slower than the plain old CMD. Fortunately, the slowness does not impact the usability of the tool, which brings you the power of .NET to the command line.

Just for a taste of how it works I have tried using some familiar objects and methods I know from programming in Visual Studio. So first off I called the ordinary "dir" command in the root folder of the C: drive and the output was more or less what would be expected:

Nothing unusual here. So where is the power of the PowerShell? The next command will say it all: "dir | foreach { $_.GetType().ToString() }" and the output for the same directory as above:

The command basically does some kind of operation: "GetType().ToString()" on each object thanks to the "foreach" command. As you can see, everything is an object in the PowerShell and as such you can execute methods on it or use it's properties. That is what I call Power Shell! Where are the linux shells hiding now :-)

As a side note. I really think Microsoft should do something to make the standard black window for the shell somewhat more usable - whatever that means. One feature that I would like the most would be the autocompletion of command parameters. I have seen this on one of the unix-like systems so it certainly is possible! Nevertheless PowerShell will rock even without it!

kick it on DotNetKicks.com