Powershell uses .Net DLL is pretty simple

Step1 :Create a  C sharp DLL project like below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SimpleMathLib
{
    public class MathDll
    {
        public MathDll() 
        { 
        }

        public static int Sum(int a, int b)
        {
            return a + b;
        }

        public int Mul(int a, int b)
        {
            return a * b;
        }
    }
}

Step 2: Use Powershell to load and use this class:
#Load Simple Math Dll.
[Reflection.Assembly]::LoadFile("C:\Users\zhangwe\Documents\Visual Studio 2010\Projects\SimpleMathLib\SimpleMathLib\bin\Debug\SimpleMathLib.dll")

#Use static class method.
[SimpleMathLib.MathDll]::Sum(1,2)

#New an object
$mathInstance = New-Object SimpleMathLib.MathDll

$mathInstance.Mul(2,3)


좋은 웹페이지 즐겨찾기