Chapter 35. Working with .NET Framework objects

 

This chapter covers

  • Understanding .NET terminology
  • Using .NET classes
  • Creating .NET instances

One of the most powerful aspects of PowerShell is the fact that it’s built on the .NET Framework and that it can access all of the underlying .NET capabilities. The .NET Framework is huge, and it’s a good bet that you can find something to do what you need in the event no cmdlet is available for the task at hand.

We have to issue a warning here, though: We’re crossing the line. You’re no longer using PowerShell as PowerShell; you’re diving into the world of .NET programming, and you just happen to be using PowerShell as a way of getting to .NET. You’ll need to use programming-style structures, rather than commands. Though this is something PowerShell can do, it isn’t something PowerShell necessarily excels at; if you’re getting into complex scripts that use .NET heavily, you might have a better experience getting a copy of Visual Studio, which is designed specifically for .NET programming.

Tip

PowerShell syntax was created to be deliberately similar to C#. That was done to provide as smooth a transition as possible for the situation where you need to use a .NET language to get your job done. Having said that, we don’t expect many IT pros to progress down that path. It’s an option, not a necessity.

35.1. Classes, instances, and members

35.2. .NET Framework syntax in PowerShell

35.3. .NET support in PowerShell

35.4. Accessing static members

35.5. Finding the right framework bits

35.6. Creating and working with instances

35.7. Summary

sitemap