Working with .NET in PowerShell
In this section, we are going to look at some of the details of how PowerShell accesses .NET libraries. We’ll look at the default assemblies, how PowerShell finds types, and another way of creating objects.
Why bother?
PowerShell and C# are part of the .NET family and thus work well together, as they are based on the same .NET foundation. They share many features, such as classes and libraries. We can call C# inside PowerShell by using Add-Type
, allowing us to compile and run the C# code when we run the PowerShell script. This lets us take advantage of the simplicity and ease of PowerShell, but we have C# available whenever we need it, without having to write an entire program.
PowerShell assemblies
We saw at the start of the chapter that we could list the loaded assemblies with the statement:
[System.AppDomain]::CurrentDomain.GetAssemblies()
AppDomain
is a class that encapsulates and isolates the execution environment; it’...