Creating a C# Extension
For most day-to-day operations, the commands provided by PowerShell, from Windows features, or third-party modules, provide all the functionality you need to manage your systems. In some cases, as you saw in “Leveraging .NET Methods,” commands do not exist to achieve your goal. In those cases, you can use the methods provided by .NET.
There are also cases where you need to perform more complex operations without PowerShell cmdlet or direct .NET support. You may, for example, have a component of an ASP.NET web application written in C#, but you now wish to repurpose it for administrative scripting purposes.
PowerShell makes it easy to add a class, based on .NET language source code, into a PowerShell session. You supply the C#’’ code, and PowerShell creates a .NET class that you can use the same way you use .NET methods (and using virtually the same syntax). You use the Add-Type
cmdlet and specify the C# code for your class/type(s). PowerShell...