[G3]-TechNews : Home| RSS | Atom | MSN | WAP

Article: Step-by-Step Guide: How to set up a VPN
Article: Download: Microsoft Monad (Beta)
Article: Building a 64-Bit Multimedia Workstation
Article: Coming Soon to Windows: The Microsoft Shell (MSH)
Article: How to Reset Win NT / 2000 / XP Administrator Password
Article: The Technology Behind Dual Core CPUs
Article: How-To: Wireless Network Security
Article: Article: PCI Express - technology backgrounder
Article: Tutorial: Access Hidden Files on Your iPod
Article: Troubleshooting drivers with XP's hidden Driver Verifier Manager
Article: How to Make a 5 in 1 Network Cable
Article: Comparison - Blu-ray & HD DVD
Article: Beginners Guides Linux : Part 1 | Part 2 | Part 3
Article: How To Crack WEP (Wired Equivalent Privacy)
Article: Email Addresses Spoofing.
Link: Free PHP ebook
Link: FREE ASP.NET books and eLearning course
Link: Free registration code for Opera 8.
Invitations: Gazzag (Here) | Yahoo! 360 (Here)  | Orkut (Here)

Article: Coming Soon to Windows: The Microsoft Shell (MSH)
Contributed by: G3nu1n3, at 6/10/2005 09:25:00 PM.

Microsoft is introducing a new command-line shell, codenamed Monad, into Longhorn. If you have a Longhorn build, you can use the new shell by launching "msh.exe."

With the advent of a new Command Line Interface (CLI) entitled MSH, Microsoft has greatly simplified server administration.

Systems administrators can now learn about .NET classes while developers can easily extend the functionality by adding "MONAD" commandlets and providers; this is known as the "Glide Path".

This article will show the syntax usage for the CLI as well as how to create basic commandlets.

The Problem

Before we delve into some of the usage for the new command shell, let's take a look at the weaknesses of the current shell to understand the direction Microsoft is moving in.

First, there is little consistency with third-party utilities or between existing shell commands in cmd.

For scripting, there is the functionally limited "BAT" (batch) method. Most importantly for the world of managing rich UI personal computers, it is very difficult to interact with some of the more graphical parts of previous Windows versions. Microsoft has stated that they made it a priority to try to make every single configuration available from both the command prompt and the GUI, from Windows 2003.

The Future

MSH (Microsoft Shell) allows the administrator to get more comfortable with the .NET framework classes if they so desire.

This also serves to provide a common area of interest between programmers and sysadmins. Drives can be made out of providers and other rich functionality can be added easily to the command prompt. Other features, such as a "-whatif" directive, can serve to improve the quality assurance process of newly created providers or commandlets. Commandlets can allow the administrator or developer to extend the core functionality of the provided commandlets by piping information either from them, through them, or to them.

New Potential

Because all existing .NET classes are now fair game as additional functionality, there is a wealth of valuable material already floating around the .NET community. Imagine how easy it would be to write a commandlet that uses reflection on objects passed from remote servers for diagnostics, or even a system monitoring commandlet that hits a mission-critical Web service to ensure the Web service is still active. Through piping commands, the "monadic" components can even build on the functionality of other components to cascade results of one command as the inputs of other commandlets.

A commandlet's syntax is in the form of "verb/noun [-parameters...]" with the handling of the parameters as mandated by the framework. This removes the flaws of the previous model where parameters could be in the form of /xyz or -xyz and it was up to the end user to read the documentation for each application to use the product. The new MSH provides a unified syntax where a user can already be prepared to script with new commandlets simply by building on the knowledge already attained through previous experiences.

Creating a Commandlet

Sample commandlet: get/machinesettings
using System;
using System.Diagnostics;
using System.Management.Automation;

namespace GetMachineSettings
/// Get/Machinesettings

[CmdletDeclaration("get", "machinesettings")]
public class GetPs: Cmdlet
public string MachineName=Environment.MachineName;
public override void StartProcessing()
WriteObject("Current Machine Info");

[ParsingPromptString("Enter either MACHINE for machine "
+"information or ENVIRONMENT for environment variables")]
public string InfoType;

public override void ProcessRecord()
if (InfoType.ToLower() == "machine")
WriteObject("Computer Name: " +
WriteObject("OS: " +
WriteObject("System Directory: " +
WriteObject("Current User Name:" +
WriteObject("FrameworkVersion: " +
else if (InfoType.ToLower() == "environment")
WriteObject("Invalid selection; accepted values " +



To begin, the first step in creating a commandlet is to import the System.Management.Automation namespace. This allows you to use the attributes necessary to create it.


The verb/noun pair in the CommandDeclaration attribute are the command pair registered in MSH when you go to run the shell. In this case, the pair is get/machinesettings because it will expose information about the machine and its settings. All commandlets derive from the Cmdlet base class that provides many methods that can be overloaded to expose even more functionality than this simple example.

The -ing and -ed suffixes added to the method names are the result of a new nomenclature for events in the 2.0 (1.2) framework. The first method shown is StartProcess(), which is called at the start of every process request. ConfirmProcessing and EndProccessing are also available, but in this example, most of the work is handled by the ProcessRecord method. This checks an input parameter to see which type of machine information the user wants, and writes out the objects to the console (or pipes to an output formatting commandlet at the request of the user).

The way MSH takes input parameters is through the attribute ParsingMandatoryParameter. We can specify the prompt when the user fails to provide the parameter on the commandline by using the ParsingPromptString attribute. If some security is needed, say for a server password, the ParsingPasswordParameter attribute is provided.

The Larger Picture

Now that an implementation of a commandlet has been shown, applications should be obvious. By extending this base class, a collection of server objects (the machines in your company) could be made, with this very same Environment information exposed via secure Web services. From there, a commandlet could very simply give an administrator instantaneous access to critical information about those machines.

One of the best new features about this shell is the fact that the actual objects are being written out. This means that the results can be stored inside an array, or passed actually as the original object to the next command in the pipe. For example, the dir command (just an alias to get/children) can be stored in an array by using variable definitions beginning with "$". Note that comments start with "#". The Length string is shown for illustration below, but in reality this may be any public property on the object being written out.

print $(get/children)[3] #prints out the third file
$a = get/children #stores dir in a varable $a
print $a[3].Length #prints out how large $a[3] is.

For navigation, a stack is available so that you do not have to lose your trail if you are moving from one directory to another. Rather than using the available set/location, you can opt instead to push/location so that you may simply pop/location to return to your previous directory. Data stores are easy to deal with at the command prompt level now because they are made to mimic file systems. This means that if you want to expose something and have it easily navigable, you need only provide the appropriate navigation provider for your data store. In future articles, this will be shown step-by-step.

This example very simply writes out machine information based on user input.

Source: Article @ Dev.com

To Read MOST UPDATED News Items browse to HOME page.


Post a Comment

<< Home

[G3]-TechNews : Home| RSS | Atom | MSN | WAP

Archives :

- Monthly Archives :

- Post Count: 1,783 before June 1, 2005. (Since: October 26, 2004)