PowerShell Cookbook

Twitter Updates

    follow me on Twitter

    Search

    Categories

     

    On this page

    Pithy and Readable? Do tell!

    Archive

    Blogroll

    Disclaimer
    I work for Microsoft.

    The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

    RSS 2.0 | Atom 1.0 | CDF

    Send mail to the author(s) E-mail

    Total Posts: 235
    This Year: 12
    This Month: 0
    This Week: 0
    Comments: 634

    Sign In

     Wednesday, February 22, 2006
    Wednesday, February 22, 2006 6:23:51 PM (Pacific Standard Time, UTC-08:00) ( )

    A long time ago, Raymond Chen wrote about how to interact with the ShellWindows COM object using C++.  It was doable, but clumsy.  He then revisited his post, showing how much easier it was when accessed through a scripting language as its designers had intended.  As can be expected, the comments flowed fast and furious in illustration of the conciseness of various languages that the readers were fond of.

    I’ve been meaning to show the Monad equivalent – not just because it is pithy, but because it is pithy and meaningful.  As MOW points out, it is amazing how frequently this happens.

    The purpose: list the title and location of all open explorer windows:

    [D:\Temp]
    MSH:46 > (new-object -com "Shell.Application").Windows() | select LocationName,
    LocationUrl

    LocationName                            LocationURL
    ------------                            -----------
    Smash Dance Hits                       
    file:///H:/lee/My%20Music/Dance/Vari...
    scriptomatic                           
    file:///C:/temp/scriptomatic
    Administrative Tools                    file:///C:/Documents%20and%20Setting...
    The Old New Thing : Using script to ... http://blogs.msdn.com/oldnewthing/ar
    ...

    Vivek makes a similar point in his latest post: It’s a one line world.  You don’t need to be a scripting guru to unleash the power of Monad:

    When we started designing the Exchange cmdline and scripting interface, we made absolutely sure that 80% of our customers, who normally have little or no scripting experience, can still use Monad/Exchange cmdline to auotmate or perform their tasks.
    (…)
    You can write lots of complicated scripts, but the majority of time, you simply have to construct a one or two line pipeline.

     

    [Edit: Monad has now been renamed to Windows PowerShell. This script or discussion may require slight adjustments before it applies directly to newer builds.]