O'Reilly logo

Monad (AKA PowerShell) by Andy Oakley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How Variables Relate to the .NET Framework

Scattered across the examples we've seen so far have been a number of references to the .NET Framework, which was introduced in Chapter 3. We'll now take some time to look at the deep relationship between MSH and the .NET Framework and several of the ways that it brings additional functionality to the shell.

Given the number of classes available in the Class Library, it's impossible to cover each in turn. We'll look at a few examples that lead the way and illustrate what the tight integration with the .NET Framework allows. An understanding of what is possible will likely become invaluable as you use MSH to approach more tasks that are increasingly complex.

How Do I Do That?

Let's start by reviewing a syntax we've already encountered: square brackets ([ ]). When square brackets are used in a script, they indicate to the shell that the enclosed term is a .NET Framework reference. A reference may be in the form of a fully qualified class (such as [System.Xml.XmlDocument]), a class name within the System namespace (such as [string]), or one of several shortcuts (such as [Xml] and [Regex]).

We've already encountered different variable types (such as int, double, string), and it is no coincidence that each one is based on a .NET class. MSH does its best to automatically infer underlying types when working with data. The type conversion rules follow a predictable pattern. If the value looks like a number, it will be converted to either an int (whole ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required