Preface

Monad is the code name for the new interactive command-line and task-based scripting technology in Windows. Also known as MSH, it is the next generation of the Windows command shell that provides a new way of thinking about a wide range of administrative tasks. At last, to the relief of administrators and power users everywhere, the command line is truly becoming a first-class citizen in the world of Windows system management.

I wrote Monad to give you a first look at the MSH command shell, and to get you to start using it as quickly as possible. You won’t find this book to be the comprehensive tutorial or dry reference manual that typically accompanies a new product like MSH; rather, it’s an exciting hands-on tour of the most useful new capabilities that MSH brings to the table.

Who This Book Is For

From administrators to developers to power users, MSH has something for everyone. If you’re someone who finds your fingers habitually drifting toward the c-m-d keys, who knows all of the switches to most command-line tools, or who spends time authoring batch files to solve new challenges, this book is definitely for you.

MSH has wide appeal. If you have a background in using other shells (on Unix-like platforms, for example), keep reading: console-based command-line interaction in Windows has come a long way and there’s plenty of new stuff to see. Even if you’re just intrigued by this new technology, the content in this book doesn’t assume any specialized domain knowledge; you may find your toolbox just gained another tool.

How This Book Is Organized

Monad consists of seven chapters and two appendixes. Each chapter has a series of hands-on labs that show you how to use MSH to complete a particular task. Some labs familiarize you with key concepts, such as how to use the pipeline, while others show you how to perform common tasks, such as displaying the contents of a registry hive. Each lab introduces a task, shows you how to do it, and explains what happens when MSH runs the command or script used in the lab. In addition, each lab tries to answer common “What If...” questions and offers suggestions for further reading.

Chapter 1, Introducing MSH

Covers the basics, such as downloading and installing the shell itself, using the MSH noun-verb syntax, passing information via a pipeline, and displaying data in the console.

Chapter 2, Customizing MSH

Moves into the command shell usage, including writing and running scripts, time-saving techniques, and personalizing the default MSH environment.

Chapter 3, Scripting MSH

Looks at the relationship with the .NET Framework, and contains the details of the scripting language with its objects, variables, script flow techniques, and functions.

Chapter 4, Managing MSH Scope and State

Dives into some of the deeper aspects of the scripting language, such as variable scope, as well as topics in string manipulation and error handling.

Chapter 5, Adding to the MSH Toolkit

Introduces a handful of indispensable commands that come standard, and teaches how to load and save data, as well as how to use the .NET Framework and Component Object Model (COM) extension points.

Chapter 6, Working with Operating System Components

Covers interaction with the Windows infrastructure, including the event log, system services, and WMI.

Chapter 7, Putting MSH to Work

Shows some practical applied uses of the shell, including interoperability with cmd.exe-based tools, batch file migration, and a library of useful MSH hacks.

Appendix A, Syntax and Grammar

Provides a quick reference guide to the language of the shell, broken out by commands, data types, variables, and language constructs.

Appendix B, Standard Cmdlets, Functions, and Aliases

Lists the built-in commands with a brief description of each.

What You Need to Use This Book

To get the most out of this book, you need a system running one of the following Microsoft Windows platforms:

  • Microsoft Windows XP SP2

  • Microsoft Windows Server 2003 SP1

  • Microsoft Windows Vista (formerly known as Longhorn)

You’ll also need a running copy of MSH. Although the examples stand on their own, there is much to be learned by trying them out, tweaking them, and extending them for other purposes. For detailed instructions on how to download and install the command shell, see "Get MSH" in Chapter 1.

Programming or scripting skills are not a prerequisite to enjoying this book. I’m confident you’ll find that most of the content of Monad is relevant to system administrators, developers, and power users alike.

Conventions Used in This Book

The following typographical conventions are used in this book:

Plain text

Indicates menu titles, menu options, menu buttons, and keyboard accelerators (such as Alt and Ctrl).

Italic

Indicates new terms, URLs, email addresses, filenames, file extensions, pathnames, directories, and Unix utilities.

Constant width

Indicates commands, options, switches, variables, attributes, keys, functions, types, classes, namespaces, methods, modules, properties, parameters, values, objects, events, event handlers, XML tags, HTML tags, macros, the contents of files, or the output from commands.

Constant width bold

Shows commands or other text that should be typed literally by the user.

Constant width italic

Shows text that should be replaced with user-supplied values.

Tip

This icon signifies a tip, suggestion, or general note.

Warning

This icon indicates a warning or caution.

Using Code Examples

This book is here to help you get your job done. In general, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission.

We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: "Monad by Andy Oakley. Copyright 2006 O’Reilly Media, Inc., 0-596-10009-4”

If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at .

How to Contact Us

Please address comments and questions concerning this book to the publisher:

O’Reilly Media, Inc.
1005 Gravenstein Highway North
Sebastopol, CA 95472
(800) 998-9938 (in the U.S. or Canada)
(707) 829-0515 (international or local)
(707) 829-0104 (fax)

We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at:

http://www.oreilly.com/catalog/msh

To comment or ask technical questions about this book, send email to:

For more information about our books, conferences, Resource Centers, and the O’Reilly Network, see our web site at:

http://www.oreilly.com

Safari® Enabled

When you see a Safari® Enabled icon on the cover of your favorite technology book, that means the book is available online through the O’Reilly Network Safari Bookshelf.

Safari offers a solution that’s better than e-books. It’s a virtual library that lets you easily search thousands of top tech books, cut and paste code samples, download chapters, and find quick answers when you need the most accurate, current information. Try it for free at http://safari.oreilly.com.

Acknowledgments

I’d like to thank the reviewers—Robbie Allen, Alex Angelopoulos, Adam Barr, Leonard Chung, Lee Holmes, and Jon Newman—for their valuable feedback during the writing process. I’d also like to thank John Osborn of O’Reilly for his guidance and patience with this book. Special thanks also go to Chris Sells for opening the door to this opportunity.

None of this would have been possible without the hard work of the people of the Monad team at Microsoft who have done a fantastic job of building a great tool.

Finally, I’d like to thank Katie Shangraw for her support and all of my friends and family who have, at times, been left wondering “Where is Andy?” during the writing of this book.

Get Monad (AKA PowerShell) now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.