Are You Yearning for a Windows Command Shell with More Oomph than CMD.EXE?

Of course you could go with KSH, CSH or BASH but let’s face it, those shells just seem alien on Windows starting with how they (KSH at least) gets confused with paths like C:\tab\newline.  Microsoft has something that can satisfy this yearning and it is called Microsoft Command Shell (MSH).  It’s also known by its codename – Monad.  I have been using MSH as my primary shell for the past week or so and even though it is still Beta code, I must say that I like it.  I like it a lot.  Yeah there are few bugs which is to be expected with beta software.  The nice thing is that the last drop was built against .NET 2.0 RTM bits so if you have VS 2005 RTM installed you are set to go.  If not you can download and install the .NET 2.0 RTM bits from here.  The MSH install download itself is tiny and can be found here.

Make sure you have .NET 2.0 RTM installed before attempting to install MSH.  After you have unpacked it and installed MSH be sure to download the documentation pack and then check out the docs.  I recommended going through the MonadScripting-HandsOnLab.doc first followed by the GettingStarted.doc.  One thing you are likely going to want to do is set the ExecutionPolicy to unrestricted.  See the bottom of page 46 of the Getting Started doc for instructions on how to do this. You can get good support on nntp:microsoft.public.windows.server.scripting

After you have created your own Profile script, consider this for your prompt function:

function prompt {
    # Display the history ID number of the next command
    $history = @(get-history)
    if ($history.Count -gt 0) {
        $lastItem = $history[$history.Count – 1]
        $lastId = $lastItem.Id
    }
    $nextCommand = [int]$lastId + 1
   
    # Display a ‘$’ if normal user and a ‘#" if admin
    $status = ‘$’
    $adminSid = [Security.Principal.WellKnownSidType]::BuiltinAdministratorsSid
    foreach ($sid in $($([Security.Principal.WindowsIdentity]::GetCurrent()).Groups)) {
        $txSid = $sid.Translate([Security.Principal.SecurityIdentifier])
        if ($txSid.IsWellKnown($adminSid)) {
            $status = ‘#’
            break
        }
    }
   
    # Determine what nesting level we are at (if any)
    $nestedStatus = ”
    if ($nestedpromptlevel -ge 1) {
        $nestedStatus = "<<${nestedpromptlevel}>> "
    }

    # Output prompt string
    "[$(get-location)]`n" +
    "MSH:$nextCommand " + $nestedStatus + "$status "
}

I’ll post more functions, filters and aliases in the future.

Advertisements
This entry was posted in Monad. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s