Chapter 22. Crossing the line: utilizing the .NET Framework

 

Until now, we’ve focused on keeping you entirely within PowerShell. Everything we’ve shown you to this point has utilized native PowerShell commands, techniques, and capabilities. The sole exception was our brief dip into databases, which required us to utilize the underlying .NET Framework. In that case, we still tried to hide the Framework a bit by providing you with PowerShell-style functions to use for database access. We’ve taken this approach because we truly believe that PowerShell is at its easiest and most consistent when you use it in the way we’ve been doing.

In this chapter, we’re going to cross the line and use the Framework more directly. This isn’t an approach that we advocate when you can accomplish your task using native PowerShell capabilities, but we recognize that sometimes you can’t rely solely on what’s built into, and for, PowerShell. There’s a price to pay for using the Framework, though: We’re exiting the somewhat tidy world of PowerShell. There will be no built-in help, and the online documentation we’ll rely on is written for professional programmers, not administrators or scripters. Our PowerShell scripts will necessarily start to look more like C# applications, and we’ll have to rely more on programming techniques than on command-line approaches.

22.1. .NET classes and instances

22.2. Static methods of a class

22.3. Instantiating a class

22.4. Using Reflection

22.5. Finding class documentation

22.6. PowerShell vs. Visual Studio

22.7. Lab