PowerShell Cookbook

Search

Categories

 

On this page

Shoe tying revolution! Ian's Shoelace Site
How to get Monad Training?
Source Code and the Monad Community
Seattle Commute Times Visualilizer
Another big Monad blogger splash
Introduction to Cryptography
Pithy and Readable? Do tell!
MSN Search, without the carpal tunnel syndrome
MSH Logo – allowing users to extend its functionality
It doesn't matter if search engines lie

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: 214
This Year: 14
This Month: 1
This Week: 0
Comments: 522

Sign In

 Tuesday, March 14, 2006
Tuesday, March 14, 2006 3:13:53 PM (Pacific Daylight Time, UTC-07:00) ( )

Peter Provost unearthed this site the other day, and it’s really great. It’s called “Ian’s Shoelace Site,” and he’s got lots of cool things to do with your laces.  That’s all well and good if you are a knot fiend, but he’s also got two very practical knots:

Believe it or not, my daughter and I spent Sunday afternoon tying our shoes!

Comments [0] | | # 
 Friday, March 10, 2006
Saturday, March 11, 2006 12:03:59 AM (Pacific Standard Time, UTC-08:00) ( )

This question has come up several times internally, so I thought I'd post my answer for posterity.  "My customer would like Monad training -- are there any courses avialable?"

Usually, these customers are looking for a good introduction to Monad – and not really training on the scripting language or development.  The best thing is probably to introduce them to our 2 recorded Live meetings:

http://msevents.microsoft.com/CUI/WebCastEventDetails.aspx?culture=en-US&EventID=1032277851&CountryCode=US
http://msevents.microsoft.com/CUI/WebCastEventDetails.aspx?culture=en-US&EventID=1032277853&CountryCode=US


If you want to really make it a hands-on experience, you could ensure that everybody has Monad installed on their machine, and watch these webcasts together.  That way, you can play with it as you learn about it.

If you want to progress further into the scripting and development aspects of Monad, the “Monad Documentation Pack” is a great resource.  Start with the "Getting Started" guide.  You can also bring in a continental breakfast, a few urns of coffee, and go over the scripting, cmdlet, and provider labs from the PDC:

http://www.microsoft.com/downloads/details.aspx?FamilyID=6387c46b-4753-4eaf-8d8b-368074f39ccc&displaylang=en

For those that learn by book, O’Reilly’s Monad book is a great place to start:
http://www.amazon.com/gp/product/0596100094

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

Comments [0] | | # 
 Tuesday, March 07, 2006
Tuesday, March 07, 2006 11:04:23 PM (Pacific Standard Time, UTC-08:00) ( )

The Monad community is vibrant, and loves to write stuff.  Even better, is that they love to share that stuff.  Sometimes, even with source code.  Jeff’s JaMSH is one example of a project that has shared its source code, and Karl seems to have intentions to share the source for his MshAnalyzer.  Taken even broader, several of our resident newsgroup gurus have been bantering around the idea to create a shared workspace for MSH extensions – likely to be called “Community Extensions for MSH.” 

On the team, we love to play with these things – and even provide feedback on how they are implemented.  Sometimes, though, the licensing terms can prevent that.

If you contribute source code to the community (such as the Community Extensions for MSH workspace) and place it under an open source license, please be aware of the implications that the license type may have.  Some open source licenses (ie: the GPL) may prevent employees at Microsoft and other companies from being able to review or provide feedback on your source code.  The BSD style license is an example of an open source license type that will be easier for proprietary software companies to work with.

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

Comments [0] | | # 
 Wednesday, March 01, 2006
Thursday, March 02, 2006 7:06:00 AM (Pacific Standard Time, UTC-08:00) ( )

When I was first looking for a house, one of my primary constraints was commute times.  I started by asking people – “How long does it take you to commute to work?”  I started building a mental map, but then started thinking about putting pins on a real map to help me remember all of the data I was getting from people.

But then I thought, “Hey – computers are supposed to make this kind of stuff easier.”  And then, “Hey – I’m a software developer.  I’m supposed to make programs that make computers do useful things.”

So I did.  I built a website that allowed people to enter everything they knew about their commute times, and then another page that let them visually explore the data set.  For example, “Find me all commute times less than 30 minutes that let me commute to work by bus before 8:30 in the morning.”

With well over a thousand data points, it’s pretty useful.

When the Virtual Earth team stabilized their API a while back, I turned it into a mashup.  So if you’re thinking about commuting around the Seattle area, enjoy:

http://www.leeholmes.com/projects/commute

P.S: Although I wanted to use AJAX for the gimmick factor, it would have made the site perform terribly!  Given the expected usage pattern, it is much more efficient to download the entire data set at once.

Comments [3] | | # 
 Monday, February 27, 2006
Tuesday, February 28, 2006 6:51:13 AM (Pacific Standard Time, UTC-08:00) ( )

Without a doubt, we are blessed here on the Monad team with a community of very talented bloggers.  To add another to the list, we are now joined by Karl Prosser.  His first few blogs are doosies – integrating Monad with SQL server, and hosting Monad in an interface very similar to SQL’s Query Analyzer.

Keep up the great work!


 

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

Comments [1] | | # 
Tuesday, February 28, 2006 5:40:57 AM (Pacific Standard Time, UTC-08:00) ( )
Cryptography is one of the areas about security that many feel is difficult to approach.  Encryption, certificates, signatures, public keys, hashing -- these are terms that most people like to keep at arm's length.
 
That is until you've read a good introduction to the subject. Although the topic of cryptography is large and very deep, a good introduction easily provides the concepts in which to frame your thoughts and discussion on the subject.  At the very least, it can help give you an idea about what that big mess of text is at the bottom of types.mshxml :)
 
For this purpose, I've always held Phil Zimmermann's "Introduction to Cryptography" paper in high regard.  You can find it at ftp://ftp.pgpi.org/pub/pgp/6.5/docs/english/IntroToCrypto.pdf.
 
Phil Zimmermann created PGP, a very early suite of encryption software.

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

Comments [2] | | # 
 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.]

Comments [1] | | # 
 Wednesday, February 15, 2006
Thursday, February 16, 2006 5:15:24 AM (Pacific Standard Time, UTC-08:00) ( )

As their blog  has so far failed to point out, it looks like MSN Search pushed a new release live today.  Unfortunately, I can’t find any mention anywhere on the internet about what’s new. 

I very much like the new colour scheme, though.  It’s light.  It’s fresh.  The old blue box made me feel constrained, but the impact goes deeper than that.

When I worked on Encarta, there was a MSN-wide effort to move to the white theme.  One of the major factors was perception: people feel that sites with minimalistic palettes load faster.  Even if the only change is to the background colour in a stylesheet.

When I implemented this change for Encarta, that was the majority of the work.  Here, try for yourself:

[Before]: http://web.archive.org/web/20050331084437/encarta.msn.com/
[After]: http://encarta.msn.com/

Oh, and Robert?  Rounded corners are so 2003 :)

Anyways, that’s a digression.

The topic often comes up at work (and online) about how much effort it takes to type search.msn.com.  It’s true – no matter which keyboard layout you use, it just feels awkward.

So, here is my contribution to the solution:

http://ouhn.net (for all Dvorak lovers out there – represent!) and
http://sfjl.net (for all of you mainstream types.)

All on the home row, and much quicker to type than Google.

Comments [0] | | # 
 Monday, February 13, 2006
Tuesday, February 14, 2006 7:48:45 AM (Pacific Standard Time, UTC-08:00) ( )

In the last article, we continued to develop our version of MSH Logo.  In typical software-geek fashion, we designed a train-wreck for a user interface.  Rather than provide our users with the power required to make fancy graphics, we shackled them with a handful of ineffective commands.  But it was all we thought the users needed!

Many situations aren’t even this clear-cut.  For example, the Microsoft Office System is a phenomenal suite of applications.  It has more features than you could ever want to count.  But that still isn’t the whole story.  The scripting support in Microsoft Office turns it into an infinitely extensible, bona fide, application development platform.

Roy Osherove goes over some great approaches to adding scripting support to an application, and we’ll take a similar approach by hosting the Monad engine.

To do this, we’ll tack on another page to our tab strip, and place a textbox in it.  We’ll also include a button that users can press to execute the MSH script inside.  We will expose a single extension point to the user – our Turtle object – which they can control with much greater ease than our ridiculous hyperlinks on the other tab.

The code that sits behind the “Run” button is quite simple.  After adding references to the required Monad assemblies, we:

  • Create and open a Runspace
  • Expose our Turtle object to scripts in the Runspace
  • Create a Pipeline inside the Runspace, populated with the user’s script
  • Invoke the Pipeline
  • Clean up.

In 6 lines of code, our application is now scripting-enabled.

private void run_Click(object sender, EventArgs e)
{
    drawingSurface.DrawImage(savedImage, 00);

    // Create and open a Monad runspace.  A runspace is a container 
    // that holds Monad pipelines, and provides access to the state
    // of the Runspace session (aka SessionState.)
    Runspace runspace = RunspaceFactory.CreateRunspace();
    runspace.Open();

    // Create a variable, called "$turtle" in the Runspace, and populate
    // it with a reference to the turtle object in our host.  Pipeline
    // commands can interact with this object like any other .Net object.
    runspace.SessionStateProxy.SetVariable("turtle", turtle);

    // Create a pipeline, and populate it with the script given in the
    // edit box of the form.
    Pipeline pipeline = runspace.CreatePipeline(scriptText.Text);

    // Invoke (execute) the pipeline, and close the runspace.
    pipeline.Invoke();
    runspace.Close();
    
    savedImage = new Bitmap(this.pictureBox.Image);
    turtle.Draw();
    this.pictureBox.Refresh();
}
 

You can download the completed application here: [monad_hosting_2.zip].  It includes a text file chock full of MSH Logo examples.  That includes one that I may well get fired for implementing: using the output of get-process to graph the working set of system processes.

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

Comments [4] | | # 
 Saturday, February 11, 2006
Saturday, February 11, 2006 7:04:59 PM (Pacific Standard Time, UTC-08:00) ( )

Robert Scoble recently asked the question, "Why Do Search Engines Lie?"  He calls out that the engines are usually off by a few results - with 692 results instead of a claimed 699, 100 results instead of a claimed 101, etc.  The numbers are worse when you count only "unique hits."  That gives numbers like 62 of 713, or 44 of 368.  I'm sure that developers of the respective search engines could give great technical answers to his question, but it's probably best answered rhetorically: "Who cares?"

In search engines, numbers are pointless:

  • Index size?  Pointless.  If I don't get appropriate results for my query, another search engine gets my business.
  • Number of results for your query?  Pointless.  For all intents and purposes, it might as well be capped at 30.  If you don't find your results in the first few pages, the solution is to fix your search term - not to keep on clicking.  If that doesn't work, another search engine gets my business.

In fact, I wrote a search engine at work that indexes source code.  The user interface gives no indication of either index size, or the number of results for a query.  The only buttons are "Search", and "Next."  
 

The URL maintains your current page number, of course, but all of those missing numbers?  Who needs them!

Comments [1] | | #