Here is a guide on how to load a dll from Powershell and call methods in it.
The most important part of the post are these commands:
[C:emp]
PS:25 > notepad MyMathLib.cs
(…)
[C:emp]
PS:26 > csc /target:library MyMathLib.cs
Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.42
for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.
[C:emp]
PS:27 > [Reflection.Assembly]::LoadFile(“c:empMyMathLib.dll”)
GAC Version Location
— ——- ——–
False v2.0.50727 c:empMyMathLib.dll
[C:emp]
PS:28 > [MyMathLib.Methods]::Sum(10, 2)
12
[C:emp]
PS:29 > $mathInstance = new-object MyMathLib.Methods
Suggestion: An alias for New-Object is new
[C:emp]
PS:30 > $mathInstance.Product(10, 2)
20
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…