Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to call my dll and use it in powershell script

Tags:

c#

powershell

I have my own dll which written in c#.
Now I want to call that from my powershell script.
I did the following;

[System.Reflection.Assembly]::LoadFile("E:\MyClass.dll")
$MyCompObj = New-Object MyClass.Student

But when I executing that, it giving me error
Constructor not found. Cannot find an appropriate constructor for type MyClass.Student

Am I following a wrong way to do this??
Please help me to fix this.

like image 571
Sonali Avatar asked Jul 31 '13 09:07

Sonali


People also ask

How do I register a DLL in PowerShell?

Another way to register the DLL files is by using a command-line interface like MS-DOS or PowerShell. First, we will open the command line interface from the Start Menu. In the following example, we will open the PowerShell. Now we will type the regsvr32 command like below.

How do you call a program in PowerShell?

To execute the program, you need to use the ampersand (&) sign followed by the full path of the program. Another way to execute the program is to browse to that directory and run the program. and run the program name. So far, we have executed the program with the full pathname.


1 Answers

Your class has got constructors (at least one). So create the object with the good params

$MyCompObj = New-Object MyClass.Student -argumentlist "arg1","Arg2" ...
like image 65
JPBlanc Avatar answered Sep 27 '22 21:09

JPBlanc