Jack Hughes
Jack Hughes

Reputation: 5664

Using .NET library from PowerShell

I have a PowerShell snap-in for manipulating a database. The snap-in itself is just a wrapper for the main library implemented in a separate .NET DLL all written in c#.

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

Whilst the snap-in works fine in PowerShell, I need to be able to access the implementation DLL details for things like enums and the like for passing through as arguments to the cmdlets.

Unfortunately, I can't access the contents of the classes inside PowerShell even though the classes are marked as public and everything I'm trying to access is also marked as public.

Do I have to do something special to the implementation DLL in order to make it visible inside PowerShell?

Upvotes: 13

Views: 15100

Answers (3)

David.Chu.ca
David.Chu.ca

Reputation: 38644

I used Steven's method to load dll. I prefer to use a var to load it so that you would not see result in output result:

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

Upvotes: 2

Steven Murawski
Steven Murawski

Reputation: 11270

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')

Upvotes: 5

Daniel Elliott
Daniel Elliott

Reputation: 22857

Add-Type -AssemblyName "Your.Assembly.Name"

Kindness,

Dan

Upvotes: 14

Related Questions