Monday, July 25, 2005

Monad Sample Script Page

I've been playing a lot with Monad, Microsoft's next genereate admin scripting tool (and generated a few blog pages too). To help me understand the product more, I've been playing with writing scripts. I thought a great way to get to know Monad better would be to try to convert some old VBS/WMI/etc scripts and in doing so, get to understand the langage and the underpinnings better.

To that end, I've put up a new sample scripts page at The idea is to show how MSH can do useful things. Some of the scripts can be pulled into your Profile.msh (or profile.custom.msh). As this gets executed when you start the shell, you end up with a load of cool new features in _your_ shell.

As Monad moves towards release, the community can create a huge repository of features that can leverage the basics of Monad while providing cool features for admins. In writing these scripts thus far, I've found the functions I've devloped are highy useful for me (thus far mainly useful for writing scripts and playing around with Monad). For example, I've defined my own tail, touch, head, plus tp (to run text pad, and Edit-NewFile (aliased enf) to create a new file (touch) then run tp on it to edit it. Versions of tail, head and touch are on the sample script page.

What has been most interesting is to note how, almost naturally, I've started to use the traditional admin script development model:

1. Type some lines directly in the shell. Play around and get something close to what I want. For example, I've created a new drive (web:) that points to \\maui\website\ I've also created a web: alias that does a CD to WEB: which made the 1st editing session very much more productive.

2. Pop the lines into a script file, or local function and get basically working. Once I found WEB: useful, I put the function and new-drive into my profile.tfl.msh file.

3. Add the function to #profile.msh and use it regularly. And as I use it, I start to add more 'production oriented " I found that you can't run new-drive multiple times without an error, so I added a check to the script to first check if web: exists and if only if it doesn't, should the new drive get created. I then added a test to see if the target drive exits (it won't when I'm offline for example) and fail more gracefully.

4. The next step would be to recode these functions into a cmdlet, or perhaps create my own hosting environment where these features are built-in. This is beyond me at present.

This leveraging process - writing loads of small little commands that make the job of using the command line shell usable and productive. I'm starting to build up libraries of libararies, if you see what I mean (eg something to parse WMI dates which is useful whenever using WMI and dates!) One of the down sides of the current drop is that the COM: scripting tools don't properly exist (this is coming in the next drop). But it's clear that Monad is gonna be a very interesiting, powerful and useful tool - I'm glad I've started to learn this now!

No comments: