- Table of Contents
- Introduction to the Reference Guide
- The New Itinerary for Windows Server 2008
- The Registry
- Domain Organization
- Executing the Migration Plan
- Resource Management
- Security
- Networking at the Link Level
- Network Applications
- Windows Management Instrumentation
- The Dawn of Windows Server 2008
- Windows Server By Command
Monad, the Three-Dimensional Command Prompt
Created Sep 26, 2003.
The first concept from which you have to divorce yourself when you're using Monad (which is what everybody still calls the "Microsoft Command Shell") is that you're not "in" a directory. With the DOS prompt, you're always in a directory, like a fixed location in a one-story building. In Monad, you have multiple contexts, the file structure of a hard drive being just one of them. You begin life with Monad in a directory, the same way you begin life inside a building on the ground floor. But Monad can take you inside almost any structure that's pertinent to your computer or to your network.
And just to show you how serious this is, I'm going to begin this discussion by changing contexts right off the bat, going where no command prompt heretofore has gone before:
MSH C:\>cd HKLM:MSH HKLM:\>
HKLM, as in HKEY_LOCAL_MACHINE. With a command that's generally used universally to mean "change directory," we've moved floors, in a very real sense, to the System Registry. All of a sudden, we're not in the world of drives and directories any more, but keys and values.
If you're familiar with command prompts, you probably get the idea that the part of the prompt before the right caret is the part Monad reports back to you, at the spot where the DOS prompt reports the current directory, only this time preceded by the MSH symbol. I'm only saying this to remind you that the part you type follows the right caret, just like in days of old.
To be honest, cd isn't really a command in Monad; it's an alias, or a common shortcut for a slightly longer command, but one more in keeping with Monad's verb-noun syntax. Here's how we find out which one:
MSH HKLM:\software\Microsoft\windows\CurrentVersion> get-alias cd CommandType Name Definition ----------- ---- ---------- Alias cd set-location
Right away, you get a flavor of how Monad likes to report data back to you: in named columns, like a database, even if there's only one record in the dataset. The get-alias command is one of those Monad commands that follows the set syntax, as is set-location. I almost don't need to explain set-location, but I brought up the topic of contexts, so I should draw this parallel while I have an opportunity: Think of set-location like a three-dimensional cd or chdir command. It can relocate your prompt within the current location, or it can elevate you to a new context and place you in a completely different setting.
Here is where our vocabulary changes a bit. In Monad, your prompt registers the current location. Because a location has members and properties in addition to its own identity, Monad can interpret a location as an object. Although Monad's definition of an object isn't as flexible as the concept of the same name in everyday programming, in the context of Monad, it's powerful enough to deserve the moniker. As with the earliest editions of Visual Basic—which borrowed the term "object" even without inheritance or polymorphism—in Monad, an object has variable type, members, properties, and in certain circumstances, exclusive things that can be done to them depending on their type. What's more, they can be assigned to a variable.
Since Monad uses a scripting language, that last revelation may be one of the most significant. Recall how in Windows Explorer (the file manager), to get anything accomplished when paring folders or relocating files, you often have to open two separate windows, revealing the contents of two different directories. And, with the old DOS prompt, when copying files from one folder to another within the same drive, you always found yourself typing the complete directory name (or what we'd call today the "fully qualified name"), either for the source directory (as in copy c:\windows\system\*.ini .) or the destination when your prompt was "in" the source directory (copy *.ini c:\inifiles\0493). Monad is a little more like the old Immediate Window of Visual Basic, in that you can declare a variable using the prompt, on the fly, and that the variable can refer to an object.
Here's a mind-blowing example using the Registry. Let's say I've traversed the Registry like a directory tree, and am now located at the parent of the key that handles all those processes which get started automatically (especially where those pesky Outlook viruses like to hide).
MSH HKCU:\software\Microsoft\Windows\CurrentVersion> get-childitem R*
Hive: Microsoft.Management.Automation.Core\Registry::HKEY_CURRENT_USER\softw
are\Microsoft\Windows\CurrentVersion
SKC VC Name Property
--- -- ---- --------
0 6 Run {ctfmon.exe, CursorXP, DesktopX, upda...
0 5 RunDFSRemoved {SunJavaUpdateSched, 1A:KkTrayServer,...
0 0 RunOnce {}
Notice, first of all, that I'm in the HKCU context, which Monad correctly reports as a Hive. >From the CurrentVersion key, I invoke the get-childitem command, which is Monad's equivalent of dir.
I created this tier myself as a handy catch-all for startup items I removed from the Run key, but whose identity I want to keep track of in case some other process re-installs it; this helps me keep an audit trail.
As you'll recall, there are two Run tiers in the System Registry, one for the current user context (HKCU), and another for the local machine, which applies to every user at all times (HKLM). As a result, I have two RunDFSRemoved keys. Let's say I want to bunch all the entries from HKCU into a central location in HKLM. I absolutely do not want to have to type the entire "fully qualified" hive location when I'm transferring contents from one location to the other. So I locate my prompt in RunDFSRemoved, then I create a variable that will represent this location as an object:
MSH HKCU:\software\Microsoft\Windows\CurrentVersion> cd RunDFSRemoved MSH HKCU:\software\Microsoft\Windows\CurrentVersion\RunDFSRemoved> $there = get- location
I used cd instead of set-location; old habits die hard. But in the second line, I invoked what, in VB, we call a statement of assignment; I created variable $there, which is prefixed by a $, perhaps in deference to Kemeny and Kurtz. Then I used the get-location command as though it were a function which returned the object as a result to the new variable.
To make a longer story slightly shorter, let's say I've moved back to the HKLM tier, and located the prompt in the RunDFSRemoved key of the local machine. >From here, I can still make certain I have my variable intact with a single command:
MSH HKLM:\software\Microsoft\windows\CurrentVersion\RunDFSRemoved> get-item $the
re
Hive: Microsoft.Management.Automation.Core\Registry::HKEY_CURRENT_USER\softw
are\Microsoft\Windows\CurrentVersion
SKC VC Name Property
--- -- ---- --------
0 5 RunDFSRemoved {SunJavaUpdateSched, 1A:KkTrayServer,...
Monad correctly reports the parent hive and the contents of my previous location, which I've stored in variable $there. Now I can make a sub-tier of my present location, and graft a copy of the other location here:
MSH HKLM:\software\Microsoft\windows\CurrentVersion\RunDFSRemoved> copy-item $th ere RunDFSAdminUser
With the copy-item command, I created the new key RunDFSAdminUser as a subordinate key of RunDFSRemoved, and copied all the contents from the location pointed to by $there, here. Notice the order of the parameters is the same as for the old DOS prompt copy command: "from" first, followed by "to." Just to make certain I've succeeded, I can double-check:
MSH HKLM:\software\Microsoft\windows\CurrentVersion\RunDFSRemoved> dir
Hive: Microsoft.Management.Automation.Core\Registry::HKEY_LOCAL_MACHINE\soft
ware\Microsoft\windows\CurrentVersion\RunDFSRemoved
SKC VC Name Property
--- -- ---- --------
0 5 RunDFSAdminUser {SunJavaUpdateSched, 1A:KkTrayServer,...
References
- The official Monad blog, maintained by Jeffrey Snover and colleagues at Microsoft.





Account Sign In
View your cart