3.1. The .NET Framework
Although the .NET Framework is invariably described in terms of C# and VB.NETtwo programming languages that rely on the infrastructure they provideit'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
, which is a set of instructions
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
. To complement the runtime, there is a broad
that contains all kinds of useful functions and data types.
Although MSH itself is written as managed code, the only important takeaway is that the .NET Framework redistributable is needed for any MSH work. However, for our purposes, there are two key aspects of the .NET Framework that we'll see in MSH time and again: strongly typed structured objects and the Class Library.
Most command-line administrative
, such as
, have just one or two data types: strings and integers. Creative use of strings and integers has resulted in some really clever scripts, but
and portability between different processes is often bound by a strict contract such as the exact format of string. The .NET Framework defines not only a number of standard data types, including strings and integers, but also Booleans (true/false), floating point
, and arrays (an ordered collection of many items of the same type). We call
that are declared with these types
, meaning that if a variable claims to be a double precision floating-point number, we can be confident that it really is a number and not a string or something else. There's no need to check that the data inside a floating-point number is actually in the correct format because the .NET Framework handles that.
In addition to these strongly typed variables, the .NET Framework introduces the idea of a
, which is a container that encapsulates a number of data types to represent something altogether more complex. Take a date and a time that could be represented by the string
. This is fine in the simple case, but it
apart when we want to compare one
with another; then, we need to resort to string parsing. Now instead, imagine a
class that has separate
integers, in this casefor each of the elements of the string: year, month, day, hour, minute, and second. The class defines the structure of data; when it's
with some real values, we call it an
For example, the output of
is a lot more
than converting the 12th and 13th
of a string to a number. Classes can also have
, which perform some action on the data contained inside. Two examples from the
, which shifts a date by a number of days (correctly observing month and year boundaries), and
, which returns the same instant in UTC.
The Class Library provides a wide set of auxiliary functionality, much of which is just as useful to a script author as it is to a developer. Instead of having to use addition, subtraction, and many tests, the
class lets us compare the difference between two dates with ease. Similar classes exist for text manipulation, URL parsing, low-level network communication, XML work, and many other common
. Given its broad scope, the Class Library is divided into
logical groups of classesthat are summarized on MSDN at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/cpref_start.asp. Many of the built-in cmdlets are built on top of this infrastructure, exposing its
but hiding the underlying plumbing from view.
Now, let's get back to MSH and see how all of this comes together.