Monday, November 8, 2004


Microsoft Windows Command Shell

Finally a real command shell under Windows. The new Microsoft Shell (MSH), code named Monad, is available as a beta distributed separately from Longhorn. It runs on XP, Win2k and Win2k3 with the latest Windows patches and the .NET 2.0 beta.

There are plenty of news, but the most important one is that the output of commands are objects, not text. This means that you can write 

get-process | where { $_.cpu -gt 10 }

to filter processes that takes more than 10% cpu without having to parse the output of the processes command. It also means that the script does not break if the output format change. The output can of course be serialized to xml and csv as well as plain text.

Plenty of cool new scripting stuff to have fun with, like the switch statement with regular expression support:

switch -regex ($var)
{ "word2"  {"Multi-match Exact " + $_ }
   "word.*" {"Multi-match Exact1 " + $_ }
   default  {"Multi-match Default " + $_; break}

You can create variables of any .NET type linke or .NET/ActiveX objects:

$books=[xml]"Davinci Code"
$wsh = new-object -ActiveXObject "WScript.Shell"

I got a bit nostalgic trying some of the commands. Things are a lot more *nix like. Dir is an alias of get-childitem and returns the following

d---s   nov 08 16.25             Cookies
d-r--   nov 08 15.59             My Documents
d-r--   gen 21 19.02             Start Menu

Even the help is man-like: get-help dir

  get-childitem [[-Path] pathname] [-Recurse] [-Include includeFilter]
   [-Exclude excludeFilter] [-Filter filter] [-Force] [-Names]
  get-childitem [[-Path] pathname] -Relationship relationshipName [-Property p
  Retrieves the child items of the specified location(s) in a drive.
  When -Relationship is specified, retrieves the available targets for the rel
  $ gch . * -exclude [a-e]*,*.dll -recurse -name
  Find all the names underneath the current location that don't start with the
   letters "a" through "e" or end with ".dll"

Jon's Radio has several examples of the cool stuff you can do with MSH. .

How to get it:

  • Go to
  • Log in with your passport account
  • Click the "If Microsoft issued you a guest account id"..
  • Enter the following Guest ID: mshPDC
  • Fill in the survey and wait

More info:

Via [Jon's Radio]

No comments:

Post a Comment