Chapter 3. Scripting MSH

In this chapter, we’ll discuss some of the core MSH language features that complement the features we’ve already covered, as well as how they can be used to build more powerful scripts. As we’ll be looking at the basic building blocks, some of the examples may appear rather abstract. However, we’ll keep the examples short and simple to help introduce the behavior and purpose of these new features. We’ll waste no time putting these new constructs to work as we move forward.

Before we begin, let’s look at how the .NET Framework fits into the picture.

The .NET Framework

Although the .NET Framework is invariably described in terms of C# and VB.NET—two programming languages that rely on the infrastructure they provide—it’s not just for developers. There are a number of facets to the framework, including a Common Language Runtime (CLR), which provides a common set of functionality to all .NET applications and tools. Compilers for the .NET programming languages generate managed code, which is a set of instructions understood by the CLR. When it comes time to run the managed code, the CLR converts it into native executable instructions (suitable for the architecture of the machine) and actually runs it. This whole process is largely transparent to both the developer and the end user. To complement the runtime, there is a broad Class Library that contains all kinds of useful functions and data types.

Although MSH itself is written as managed code, the only important ...

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.