Microsoft’s next generation command shell

This content is 20 years old. I don't routinely update old blog posts as they are only intended to represent a view at a particular point in time. Please be warned that the information here may be out of date.

Back in June 2004, I got in a panic because I heard that VBScript was about to be phased out. Don Jones commented that VBScript will still be there in Windows, it just won’t be developed any further, then later I heard about the new Microsoft scripting host (MSH) shell (codenamed Monad).

At yesterday’s IT Forum ’05 highlights (part 2) event, Thomas Lee gave a preview of Monad. Although I am enrolled on the Microsoft command shell beta program, pressures of work and family life have left very little time to do anything with it up to now, but having seen Thomas’ demo, I’ve installed MSH beta 3 on my day-to-day notebook computer and will try to use it instead of cmd.exe, regedit.exe and some of my other everyday tools.

Those of us who have worked with Windows since… well since MS-DOS… will remember the command prompt, as will those who use other operating systems. Graphical user interfaces (GUIs) are all very well (and a well designed GUI can be remarkably intuitive), but a command line interface (CLI) is my preference. Despite a whole load of new and powerful commands in recent Windows releases (like netsh.exe), Windows still lags behind Unix in many ways when it comes to command line operations and MSH is an attempt to catch up with, and then exceed, the tools provided by other operating systems.

MSH is a next-generation shell that is intended to:

  • Be as interactive and scriptable as BASH or KSH.
  • Be as programmatic as Perl or Ruby.
  • Be as production-oriented as AS/400 CL or VMS DCL.
  • Allow access to data stores as easily as accessing file systems.

It sounds like a tall order but amazingly, Microsoft seem to have cracked it. MSH is also pretty easy to use and, it’s secure by default, avoiding many of the issues associated with VBScript. So secure, in fact, that before running MSH you may wish to execute the following registry change:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSH\1\ShellIds\Microsoft.Management.Automation.msh]
"Path"="C:\\Program Files\\Microsoft Command Shell\\v1.0\\msh.exe"
"ExecutionPolicy"="Unrestricted"

(There’s more on MSH security below).

MSH is instantly recognisable. If I was to type cmd, I would be greeted with something similar to the following:

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\>

If I type msh instead, everything is very familiar:

Microsoft Command Shell
Copyright (C) 2005 Microsoft Corporation. All rights reserved.

MSH C:\>

Type dir and guess what happens? For that matter, type ls! If you want to see the contents of a file then either type filename or cat filename will work too. get-history returns a list of commands, to re-run, save, or edit.

Whereas Unix (and Unix-like) systems tend to store configuration in text files, Windows configurations are incredibly complex with multiple data stores (the registry, text files, DNS, Active Directory, etc.). These data stores normally fall into one of two categories: hierarchical, highly recursive data structures (file system directories, registry keys, Active Directory organizational units, etc.) or fairly flat structures (e.g. DNS zones and records). MSH makes them all easy to navigate using a system of data providers.

For example, I can type cd hklm: followed by dir to see all the HKEY_LOCAL_MACHINE keys, navigating the registry as though it were a file system. This simplicity is both elegant and incredibly powerful. There are no AD or DNS providers yet, but the next version of Exchange (codenamed Exchange 12) will include MSH support, treating Exchange databases as just another data store (get-mailbox, etc.). Exchange 12 support is not implemented as a data provider, but as a commandlet (cmdlet), because its data structure is not really hierarchical (at least down to the mailbox level) – the full list of Exchange commands can be found using get-excommand.

For example, if I want to see the details of my system, I can use get-wmiobject command. That’s a bit long to type, so I can actually use get-w and then complete the command with the tab key (as can in cmd.exe these days). get-wmiobject win32_computersystem returns the details of my system as an object with attributes, that I can assign to a variable (e.g. $mysystem=get-wmiobject win32_computersystem). After that, $mysystem.name returns the name of my computer, $mysystem.manufacturer returns Fujitsu Siemens and $mysystem.model returns Lifebook S7010. That would have been so much harder to obtain in VBscript. Take it to the next level and you can see how the data can be queried and actions taken according to the results (e.g. if ($mysystem.model -eq "Lifebook S7010") {"Do something"}).

MSH has built in help (e.g. get-wmiobject -?) and more is no longer an external command so get-wmiobject -? | more works too.

Some commands will return an array of objects, for example get-wmiobject -list. That’s a pretty long and unmanageable list but if I use $wmilist=get-wmiobject -list, I can use $wmilist.length to see how many objects were returned, $wmilist[objectnumber] to view a single object and of course I can also use $wmilist[objectnumber].attributename to refer to a single item.

On a typical Unix system, pipes are used to pass text between commands. Scripts can be used to split strings and extract data (also known as prayer-based parsing, because if the command output is changed, the scripts break). MSH pipes are .NET objects with metadata. That means that a hierarchy of objects can be passed between commands. So, I can also show my WMI array as a table by piping it through format table (ft), i.e. $wmilist | ft (fl is format list).

Having looked at how simple to use, yet powerful, MSH is, let’s look at some of the product specifications:

  • MSH is intended to support a number of different administrative levels:
  • Operators – command line only.
  • Simple scripters – simple sequences, untyped variables and functions with unnamed parameters.
  • Advanced scripters – typed variables and functions with named parameters.
  • Sophisticated scripters – scoped variables, functions with initialised parameters, function cmdlets and scriptblocks.
  • The four administrative levels are supported with different script types:
    • Text – .NET interpretations of the traditional Unix scripting model.
    • COMWindows script host (WSH)/VBScript-style scripting.
    • .NET – for manipulating any native .NET object.
    • Commands – MSH cmdlets emitting objects.
  • These script types are supported with a variety of data types, including .NET, XML, WMI/ADSI and ADO.
  • MSH is intended to be tremendously customisable and it will eventually allow dispense with the style separation between GUI, CLI and systems programming skills so that even an infrastructure bod like me will be able to issue a GUI command (or use a Win32 program) and see what the MSH equivalent command is, so that I can build my own scripts and run a task repeatedly! Unfortunately this GUI-CLI functionality has been dropped from the first release, but hopefully we’ll see it in a service pack later.

    From a security perspective, MSH is extremely secure, with four operational modes:

    • Restricted mode allows interactive operations only, with no script execution.
    • AllSigned mode requires that scripts must be signed by a trusted source.
    • RemoteSigned mode requires that scripts from the Internet must be signed by a trusted source.
    • Unrestricted mode will allow any script to run, but will always warn before remote scripts are executed.

    Other security measures include:

    • No file association for .msh files.
    • The current folder (.) is not on the path by default.

    So when can we get MSH? Beta 3 is available for download now and the final release is expected with Exchange 12. Although MSH will not included with Windows Vista, I’m told that it does work on a Vista/Longhorn platform.

    Finally, for one more example of how easy Monad can be to use, try this:

    "Monad Rocks " * 200

    Links
    Thomas Lee’s Monad information centre
    Monad on Channel 9
    Monad product team blog
    MSH on Wikipedia
    microsoft.public.windows.server.scripting newsgroup

    Microsoft’s Open XML document formats

    This content is 20 years old. I don't routinely update old blog posts as they are only intended to represent a view at a particular point in time. Please be warned that the information here may be out of date.

    There has been a lot of media and industry comment of late about Office document formats, including Microsoft’s willingness (or otherwise) to embrace open standards. Whilst there will be some limited PDF support in the next version of Office (Office 12), Microsoft is hoping that it’s submission of the new Office formats to the ECMA will be sufficient to make the new Office file format a global standard.

    In a newsletter sent to Windows Vista and Office 12 beta testers, Microsoft commented that:

    “…Word, PowerPoint, and Excel documents are now zipped files containing separate XML components. This format has just been released to ECMA and can be used royalty free.”

    They continued to extol the virtues of this approach, claiming that:

    “This means that you can build robust server side processes that manipulate and create office documents without ever needing the client [applications] running on the server. The openness of the file format means that ISVs can access the full semantic content of their documents without relying on Microsoft code to extract strings.”

    On the face of it, this sounds good, but my first impression is still “oh no, yet more explaining to customers why their users on previous Office versions can’t read documents that have been sent from Office 12 users”. Oh well, I guess that’s the price of progress, but isn’t .PDF a de facto standard for document interchange these days?

    Changing drive icons in Windows Explorer

    This content is 20 years old. I don't routinely update old blog posts as they are only intended to represent a view at a particular point in time. Please be warned that the information here may be out of date.

    A few weeks back, John Howard blogged about changing the Windows Explorer drive icons for his multimedia cards. I decided to give it a go myself and it is pretty cool, although I still can’t find a memory stick icon that I like, so that’s been left at the default setting.

    Drive icons

    One point to be aware of (that I missed in John’s post) – the DriveIcons and DriveLabel registry items are subkeys (not values) – the actual registry settings that I used are:

    Windows Registry Editor Version 5.00
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons]
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\E]
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\E\DefaultIcon]@="%systemroot%\\system32\\shell32.dll,194"
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\E\DefaultLabel]@="SmartMedia Card"
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\F]@=""
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\F\DefaultIcon]@="%systemroot%\\system32\\shell32.dll,189"
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\F\DefaultLabel]@="CompactFlash Card/MicroDrive"
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\G]
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\G\DefaultIcon]@="%systemroot%\\system32\\shell32.dll,193"
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\G\DefaultLabel]@="Secure Digital Card"
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\H]
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\H\DefaultIcon]@=""
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\H\DefaultLabel]@="Memory Stick"

    Icons don’t have to be stored within a dynamic link library (DLL) – one MSFN forum post indicates that .ICO files can be used too.

    Finally, my USB Flash Drive also has an icon. Because this could have a different drive letter depending on what other devices are connected, I didn’t use the registry approach. Instead, I saved an autorun.inf file in the root folder of the device, with the following contents:

    [autorun]
    label=USB Flash Drive (128MB)
    icon=shell32.dll,12

    Using this method the drive lable and icon change whichever computer I use the device in (provided that shell32.dll is available).

    IT Forum ’05 highlights: part 2

    This content is 20 years old. I don't routinely update old blog posts as they are only intended to represent a view at a particular point in time. Please be warned that the information here may be out of date.

    Microsoft UK IT Forum HighlightsMicrosoft do say that they like to receive feedback on the events that they run. Unfortunately, my feedback for last week’s IT Forum ’05 highlights (part 1) event was not good and Thomas Lee gave me a clear indicator today that people really do read it when he gently needled me about my comments on the quality of the external presenters (don’t worry Thomas – your VSAT scores will be excellent)!

    Whilst it makes me a little nervous that most of the IT professional technical evangelist team at Microsoft UK (and some external speakers like Thomas) know me by name (I’m probably infamous for asking too many questions and for republishing their sessions on this blog), I figure that my musings here also help spread their message and I’ve made it my unofficial role to be a bit of a Microsoft evangelist (although I still comment when I don’t like something and I also write about other technology areas that interest me).

    I’m pleased to say that today’s IT Forum ’05 highlights (part 2) event was a world apart from last week’s part 1. With good speakers for four out of the five sessions, interesting topics (and some cool technology demos), there was a whole load of information presented that I couldn’t easily get elsewhere (that’s the whole point about going to Microsoft events, I want to learn things that I can’t find on Google).

    In fact, there was so much good stuff that it won’t fit into a single blog post, so expect to see more here (as soon as I get time to write it up) about Exchange 12, the Windows Server 2003 SP1 security configuration wizard, the Microsoft Scripting Host (codenamed Monad), Exchange Server 2003 SP2 mobile messaging, and maybe a bit more about Windows Vista too.

    Release of the next Windows Vista CTP may be imminent

    This content is 20 years old. I don't routinely update old blog posts as they are only intended to represent a view at a particular point in time. Please be warned that the information here may be out of date.

    This afternoon, I heard the clearest indicator yet from someone close to Microsoft that the next Windows Vista community technology preview (CTP) release is imminent – it may even be made available as soon as tomorrow. Furthermore, as widely reported in the media, there will not be a second Windows Vista beta (there is already some confusion over this because earlier CTPs have included the magic words “beta 2” in places).

    I commented a few months back that releasing a series of CTPs as well as the normal series of beta and release candidates would be too much to fit in – it remains to be seen whether there will be further CTPs (I would expect at least one more in April) or if Microsoft will move back to the traditional release candidate model.

    Meanwhile, at least in public, Microsoft are sticking to their schedule of shipping Vista in the second half of 2006 – my gut feeling is that whilst RTM may well be achieved in 2006 general availability will not be until early 2007.

    Tips for managing digital audio

    This content is 20 years old. I don't routinely update old blog posts as they are only intended to represent a view at a particular point in time. Please be warned that the information here may be out of date.

    Paul Thurrott has just posted a useful article on the Connected Home Media site about acquiring digital media (the comments are worth a read too).

    I use iTunes (only because I have an iPod – otherwise it would be far more convenient for me to use Windows Media Player) and have ripped all of my CDs to disk as 192-bit MP3s (I still need to rip the CD singles, the vinyl records, the compact cassettes, the MiniDiscs and the DVDs), but I do disagree with Paul on one point- I still buy music on CD. I do this for a number of reasons:

    • I own a legal copy of the music without any digital rights management (DRM).
    • I have a backup copy.
    • If I buy my CDs online (or from the supermarket), it generally costs the same (or less) as buying a whole album from iTunes.

    Having said that, I did buy a couple of tracks from iTunes recently – single tracks when I didn’t want to pay an extortionate price for a CD single. I was concerned about DRM and the limitations of 128-bit AAC but using the iTunes Music Store is really easy.

    Paul’s approach of burning the legal downloads to CD and then ripping them again is a great idea (accepting that there will be an inevitable loss in quality) – at least that way I have a non-DRM copy for use in years to come.

    Finding the right memory for a PC upgrade

    This content is 20 years old. I don't routinely update old blog posts as they are only intended to represent a view at a particular point in time. Please be warned that the information here may be out of date.

    Get more memory at Crucial.com!

    Before installing Virtual Server 2005 R2 on my already overworked server (actually, its just a PC) which acts as a domain controller, DNS server, DHCP server, RIS server and handles a few file shares (admittedly on a small network – I’d never advise running a business on a single PC), I thought I’d better put some extra memory in it.

    I find it impossible to keep up with PC hardware, and at the danger of turning this post into one large advert, I was really impressed with my experience at the website. In a few clicks, I was able to use the Crucial Memory Advisor Tool to identify the memory options for my aging Compaq Evo D500SFF and, although I didn’t use it at the time, they also have a system scanner which can be used to identify upgrades for a specific system (I’ve just run it now and it correctly identified the system which I’m using to write this post).

    Another area of the Crucial site that really impressed me was the help text, which enabled me to understand the various memory types (so I could decide whether or not to simply swap some RAM around between my various systems).

    To make this post a little more balanced, I should mention that Kingston Technology also have a memory search tool but my experience was that the Crucial version was faster to use and the prices were lower (I suspect this is because Crucial sell direct whereas Kingston redirected me to a third party to actually buy the RAM). Crucial also sell flash memory cards and readers, USB flash drives, graphics cards and printer memory,as well as offering free UK shipping by Royal Mail Special Delivery for orders over £25 and guaranteeing compatibility of the memory purchased (as long as you have used the Crucial Memory Advisor Tool).

    Crucial, the memory experts

    Money-grabbing telcos want to charge for their piece of the Internet

    This content is 20 years old. I don't routinely update old blog posts as they are only intended to represent a view at a particular point in time. Please be warned that the information here may be out of date.

    Google is my search engine of choice, and Google AdSense is the main source of income for this site (still not quite breaking even though); however recently I have criticised the Internet search giant for their appalling Google Pack and also questioned (in not so many words) whether their rapid growth is starting to impinge on their “don’t be evil” informal corporate motto…

    Whether Google are evil or not, I was appalled to hear on Slashdot Review that US telcos have criticised Google and other Internet giants for using their lines without paying extra fees and charges. According to the original Washington Post article, a Verizon executive said:

    “The network builders are spending a fortune constructing and maintaining the networks that Google intends to ride on with nothing but cheap servers.”

    The way I see it is that I pay my Internet service provider (ISP) to provide an Internet service and Google pays their ISP to provide an Internet service whilst the ISPs pay the telcos for access to the carrier networks. So, the telcos are paid, not once, but twice to deliver Google’s data to my browser. Now they want to be paid again… hmm…

    At the same time, the telcos are putting in place next generation networks that will allow them to prioritise traffic, effectively allowing them to marginalise “free” Internet users, giving access to those are prepared to pay more. As both a user and a content provider, I don’t like this one bit, and neither it seems does Google’s Chief Internet Evangelist, Vinton G. Cerf, who was partially responsible for the original creation of the Internet and was reported in the same article as saying:

    “In the Internet world, both ends essentially pay for access to the Internet system, and so the providers of access get compensated by the users at each end… My big concern is that suddenly access providers want to step in the middle and create a toll road to limit customers’ ability to get access to services of their choice even though they have paid for access to the network in the first place.”

    That just about sums it up to me. Verizon (AT&T, and the rest) – keep your hands off the Internet – I pay my ISP – how ISPs and telcos charge one another for access should not be my problem.

    The IT Crowd

    This content is 20 years old. I don't routinely update old blog posts as they are only intended to represent a view at a particular point in time. Please be warned that the information here may be out of date.

    I was pleased to read in IT Week that a new sitcom was about to air in the UK, based around an IT department (I even heard about it on US-based podcasts – largely because Slashdot picked up on it). Surely, I thought, there’s plenty of scope there for something funny – maybe even a twist on “The Office” bringing in the idiosyncrasies of end-user support.

    Well, the first two episodes of Channel 4’s “The IT Crowd” hit our screens last weekend (I finally watched it last night) and I was sorely disappointed. It scored 10 out of 10 for attention to detail (office in the basement of a tower block, RTFM t-shirt, rows of defunct CRT monitors on the shelf with Post-it notes attached, Commodore PET and ZX81 proudly on display, IT Manager who knows nothing about IT, etc.) but laughs were few and far between (not counting the dubbed-on sitcom laughter), despite depicting the two techies (to support 34 floors of staff… first response to all support calls “have you turned it off and on again”) as social misfits.

    Maybe working in IT is just not that funny.

    Understanding DHCP console icons

    This content is 20 years old. I don't routinely update old blog posts as they are only intended to represent a view at a particular point in time. Please be warned that the information here may be out of date.

    A few weeks back, I was troubleshooting some DHCP issues and came across Microsoft knowledge base article 259786, which gives a link to a handy reference of DHCP console icons. Unfortunately at the time of writing, the link in the knowledge base article is broken – the DHCP console icons reference is available in the Microsoft Windows Server TechCenter.