[Mono-list] Powershell over Linux

Mike Christensen mike at kitchenpc.com
Mon Mar 1 14:55:12 EST 2010

I'll take a quick stab at answering this, though I'm far from a
PowerShell expert..

The main question is "what's so special about PowerShell" and why is
it any better than Bash or what not.  I think the primary factor is
PowerShell is not a command line interpretter but an actual CLR host
itself (similar to how SQL Server can host the CLR for extended stored
procedures).  It can load managed DLLs into memory, and provide access
into managed objects using reflection and "auto-complete" stuff on the
command line based on the object type.  Commands are nothing more than
.NET classes with properties you set on the command line, so the
parser itself can do things like auto-complete command line
parameters, resolve ambiguous parameters (-rec is the same as
-recurse).  If you write a command, you don't have to do /any/ parsing
of the command line parameters (unless you want to)..

That being said, the actual command line interpretter is totally
abstracted from the PowerShell engine.  You could embed PowerShell
into your program and run PS scripts or even write your own command
line syntax.  The engine itself allows you to do pretty nifty things
such as instantiate managed objects on the fly.  I can say:

PS C:\> 1 + 1

What I've gotten is an actual Int32 object.  I can prove it with:

PS C:\> $a = 1 + 1
PS C:\> $a.GetType().Name

Further more, any CmdLet (which you can write in managed code and
"load" into the engine) has a full object model:

PS C:\> $b = dir
PS C:\> $b.Count

The real power of this is you can pipe the results of one command into
the input of another command and refer to the actual interface of that
object.  In *NIX, you have to do a bunch of grep'ing and text parsing
to really make sense of anything.

There's also some great things such as COM interop..  Watch as I
instantiate IE on the command line and make it navigate somewhere:

PS C:\> $ie = new-object -com internetexplorer.application
PS C:\> $ie.visible = $true
PS C:\> $ie.navigate2("http://www.cnn.com")

The PowerShell team basically got a bunch of old-skool UNIX hackers
and had them sit down and design the command line environment they
/wished/ they had in UNIX.  This even included some old Amiga geeks
and long time sysadmins.  It's pretty well designed in my opinion.  I
for one would love to see something like this written on Mono, but I'm
afraid it's a long ways off from happening since it really takes
advantage of what the Windows system has to offer..


On Mon, Mar 1, 2010 at 11:22 AM, Ben Gamari <bgamari.foss at gmail.com> wrote:
> Excerpts from Andrew Brehm's message of Mon Mar 01 05:35:06 -0500 2010:
>> I feel your pain. I would also love to use Powershell on (in my case) Mac OS
>> X.
> Not to sidetrack the conversation but what exactly can you do in
> Powershell that you can't do in Bash/csh/Python/Ruby/Perl?
> It seems that Powershell is just another misguided attempt by Microsoft
> to emulate Unix facilities while ignoring the principle of orthogonality
> that gives the Unix tools so much of their power. I utterly fail to see
> why you should need yet another syntax just to do basic scripting. It
> seems they just created another language instead of fixing their
> completely useless command line shell (cmd.exe).
> I'll give Microsoft credit where credit is due (the CLR is a pretty
> excellent design and F# is a wonderful language), but command line
> scripting has never been their strength.
> - Ben
> _______________________________________________
> Mono-list maillist  -  Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list

More information about the Mono-list mailing list