25 Wrapping up the .NET Framework

 

As you begin exploring the possibilities of what PowerShell can achieve, you’ll inevitably encounter situations where there’s no prebuilt cmdlet to perform your desired task. In many instances, you may find that the extensive .NET Framework, or possibly an external command, an old component object model (COM) object, or something else, can address your needs. Can you use raw .NET components in your scripts? The answer isn’t a straightforward no, but it’s also not a definitive yes.

25.1 Why PowerShell exists

To understand this better, let’s reflect on why PowerShell exists in the first place. Microsoft Windows, as an operating system, offers an abundance of tools designed to facilitate automation. It’s inherent to the nature of computers. The challenge with Windows has always been that these automation capabilities are tailored for professional software developers and may not be user-friendly for administrators without extensive programming expertise or those pressed for time.

You could automate Windows effectively if you were well-versed in C++, C#, and other first-class Windows programming languages. However, you face difficulties if you lack this knowledge or the time to delve into these lower-level languages or their APIs.

25.1.1 A crash course in .Net

25.2 Exploring a class

25.3 Making a wrapper

25.4 A more practical example

25.5 Your turn

25.5.1 Start here

25.5.2 Your task

25.5.3 Our take

Summary