Freigeben über


My thoughts on Monad, the new Windows command line shell

Today I decided to install Monad, the new command shell for Windows and I gotta say - this thing is awesome! It's pretty much the most confusing shell I've ever seen, but it combined everything I like from DOS, Bash, Amiga, and the Visual Studio "immediate window".. Basically this thing sits around and creates managed objects in memory and returns instances of those objects.. Those instances can be echo'ed to the command line (ToString is called), or piped into another object.. You can start with simple expressions such as:

1+1

And get back "2"... You can also declare variables such as:

$x = 1+1

You can even call into managed objects such as:

$curdate = [DateTime]::Now

$curdate is actually a manged System.DateTime object, so you can do stuff like $curdate.Date right on the command line.

You can also create an instance of a COM object, such as Internet Explorer:

$ie = new-object -com internetexplorer.application

And then call methods off that such as:

$ie.navigate2("https://www.msn.com/")

The scripting language is pretty nuts and is like nothing I've seen before, but seems to be pretty powerful. However, if you get lost, you can create "CmdLets" which run in process and can be written in managed code. You can easily create CmdLets in Visual Studio, compile them as a DLL, and then call "Add-MshSnapin" on that DLL to register it within the shell. They're easy to debug by attaching to the msh.exe process. When I create a new CmdLet, I specify a verb name (such as Get or Set) and a noun name. I can define parameters for my command as properties of the class. When I run my command from the command line, it's actually creating an instance of that class in memory. If I pipe that command into something else, the actual object is being transferred in memory, not text. Using Reflection, you can also get "tab" command line completion for parameters and what not. You can "capture" all the CmdLets you have active in your shell to an .mcf file so you can easily load them later. In fact, you can create your entire own shell (CmdLets, aliases, script files, etc) and compile the whole thing as an EXE. You can override just about anything you want on the shell, and then just run that EXE as your own person shell with all your customizations that's targetted to your specific need. There's also no reason your shell needs to be command line based. I can make a GUI application that runs on top of Monad as well.

Another great feature is a total abstraction within the file system. Before, you were used to interacting with current file system objects and navigating through folders on the file system. Now, you can do all that, as well as navigate using other providers. Various "MshDrives" are installed, and you can see them by typing "Get-MshDrive". By default, you have drives for mounted disk drives, the registry, ActiveDirectory, Certificates, environment variables, and a few other things. This means you can type:

cd HKCU:\

And you're now in your HKEY_CURRENT_USER registry node. You can type "dir" to see everything and interact with objects just as if they were files.

You can create your own drives as well. I can type:

New-MshDrive -name WinDir -MshProvider FileSystem -root C:\WINNT

And now the WinDir:\ drive is mapped to C:\WinNT. This makes it easy to create shortcuts to long paths.

Since every command uses the same parser, there's various intrinsic parameters that work any any command. For example, I can add the -whatif parameter to show what my command would have done without actually doing anything. I don't really have to worry about parsing parameters on the command line. For those of you who like wildcards, they're way better now. I can pretty much use full regular expressions and search for items or commands. Since everything is an object that exposes properties, I can do stuff like "group" the files by their manufacturer, or search for any dll made by NVidia. I can also search for all processes that take up more than 5 megs of RAM.

Anyway, I could spend hours going on about this and I've only been using this for a day. I've decided to "hide" cmd.exe and use the new shell exclusively, thus forcing myself to get better with it. For a better explanation by the guy who actually designed the thing, go check out:

https://channel9.msdn.com/ShowPost.aspx?PostID=25506

And for an actual demonstration:

https://channel9.msdn.com/Showpost.aspx?postid=25915

If any of you are using this, I'd love to hear your comments and any tips and tricks you've learned so far. I'm a complete newbie and am still doing a lot of exploring.

Thanks,

Mike

Comments

  • Anonymous
    April 28, 2006
    Seems pretty powerful -- I love the idea of being able to script the .NET API.

    I wonder if I can instantate custom .NET objects from any arbitrary Monad script. I assume that would be the case if I have installed an assembly properly. I also wonder if I can use Monad from my own application, say for custom plugins and the like.
  • Anonymous
    May 03, 2006
    For those looking to install the latest beta, check here:

    http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx