Joben.Rara.blogs(".NET")

There are two ways to write error-free programs; only the third one works.

September 2006 - Posts

Powershell in fits and spurts

I've been learning Powershell (aka Monad) in fits and spurts. Sometimes, you just need *real* motivation to get you started.

In fits

You know how it is, you see a post on a blog, you get excited, you download the "thang", play around with it, then real life happens...reports, deadlines, call customer, buy milk and diapers, bring home the bacon, etc...

and spurts

After downloading that shiny new beta of Powershell IDE for the 3rd time, I gave it a few commands, then all of a sudden... the "thang" croaked, gave out an uncaught exception, and just wouldn't die. A microsecond Lightningbefore I summoned Process Explorer to kill the "thang", I wondered if there was a powershell-y way of doing this...

PS > get-help *process

That gave me

Name                       Category                   Synopsis
----                       --------                   --------
Get-Process                Command                    Gets a list of process...
Stop-Process               Command                    Stops a running process

Hmmm...interesting. Let me try

PS > get-process

    345      11    39760      40188   171     3.20   4228 powershell
    536      18    42052      53304   245     4.13   5520 PowerShellIDE
    144       5     2276        816    74     0.30   3388 Realmon
   1068      13    52544      37336   245            2492 SearchIndexer

There you are. Gotcha! So now to kill this errant process...

PS > get-process PowerShellIDE | stop-process

There you go, a one liner powershell equivalent of what I use Process Explorer most for. (No offense meant to procexp as it is such a great program that does more than kill a process)

My powershell escapades, as I said, are in fits and spurts, so I just might create my own commandlet called "kill" later on to further shorten this to "kill powershellide", but that *could* be in a later post.

And just in case you're still wondering what the heck is "Powershell", here you go my friend... http://search.live.com/results.aspx?q=powershell

Download RC1 and hope you learn Powershell faster than I am so you can start giving me tips. Stick out tongue

Posted: 09-20-2006 4:58 PM by velocity | with no comments
Filed under: