Jul 13 2008

Powershell vs UNIX Shells

Category: Software DevelopmentDmitry @ 11:15 pm

PowershellFirst of all, I love Powershell. For those of you that don’t know, Powershell is (relatively) new command-line and scripting language for Microsoft Windows platform. The Powershell team has spent a lot of time looking at existing UNIX scripting tools and in my opinion cherry-picking the best features from them. Its the best of Ruby, Perl, Zsh etc. The language syntax is very similar to Ruby and Perl. I am a big fan of both. In this article I’ll try to compare it to other unix shells and scripting languages.

Powershell vs Unix Shells

The biggest difference between Powershell and UNIX shells is object orientation - Powershell deals with (.NET) objects for input/output, and Unix shells deal with simple text character streams for IO.

If you’re dealing with objects, you’re concerned with accessing its properities and sub-objects to find things, instead of grepping through text streams in a very unstructured manner.

Powershell has built-in “commandlets” (cmdlets). Think of them as built-in commands in unix shells, such as ls, cd etc. In powershell, all commandlets follow action-verb naming convention, like Test-Path, or Get-Aliases.

This naming convention is actually very emacs-like:

Open Emacs and type M-x view-[Hit Tab]. You’ll see view-file, view-todo etc.


Anyway, to make scripting for Windows platform more accessible and attractive to UNIX devs, Powershell provides aliases that map to proper commandlets. For instance, “ls” is an alias for Get-ChildItem, “dir” is also another alias for Get-childItem:

Providers

Powershell has a layer of abstraction that lets you manage different aspects of Windows: this layer is called “providers”. So, there is a provider for dealing with the file system, registry, wmi, certificate store, variables, namespaces, functions etc.


Similar to everything in Unix being a “file”, you can get a view of most things on Windows platform using right providers. It also lets you to create your own.

Great Tab Completion Support

One of the really nice features in Unix shells is tab completion. For example, Zsh (my favorite unix shell) has versatile ways you can customize tab completion.


Powershell also has a support of tab-completing pretty much everything: variable names, functions, even .NET namespaces, classes etc. There is a plugin from Powershell Guy called PowerTab. I rely on it every day … highly recommend it.

Daily Work

I try to avoid clicking buttons if I can automate it do it quicker from a command line, so my powershell console is always opened. Its great for development - I can test and script stuff using .NET without having to compile it etc, and it is also convenient for system administration in general.

I’ll post some tips and tricks on both later on …

Leave a Reply