Using .NET from PowerShell

I have a PowerShell snap-in for database management. The snap-in itself is just a shell for the main library, implemented in a separate .NET library written in C #.

I registered both the snap-in and the implementation DLL with the GAC using installutil.exe

While the snap-in works fine in PowerShell, I need to have access to the implementation DLL data for things like enumerations, etc., to pass as arguments to cmdlets.

Unfortunately, I cannot access the contents of classes inside PowerShell, even if the classes are marked as public, and everything I try to get is also marked as public.

Do I need to do something special for the DLL implementation to make it visible inside PowerShell?

+5
source share
3 answers
Add-Type -AssemblyName "Your.Assembly.Name"

Kindness,

Dan

+6
source

Add-Type will work for PowerShell V2, as described by Daniel .

You can also use reflection in both V1 and V2 -

[System.Reflection.Assembly]::LoadFile('path to your dll')
+2
source

I used the Stephen method to load the dll. I prefer to use var to load it so that you don't see the result from the output:

 $loadLib = [System.Reflection.Assembly]::LoadFile('path to your dll');
+1
source

All Articles