Run my third-party DLL file with PowerShell

亡梦爱人 提交于 2019-11-29 23:01:50
manojlds

Yes, you can:

Add-Type -Path $customDll
$a = new-object custom.type

You call a static method like so:

[custom.type]::method()

Instead of Add-Type, you can also use reflection:

[Reflection.Assembly]::LoadFile($customDll)

(Note that even the above is calling the Reflection library and the LoadFile static method.)

Chris N

Take a look at the blog post Load a Custom DLL from PowerShell. If you can interact with an object in .NET, you can probably do it in PowerShell too.

Actually the other offered solutions don't work for me, here it's an alternative that works perfectly for me:

$AssemblyPath = "C:\SomePath\SomeLIB.dll"
$bytes = [System.IO.File]::ReadAllBytes($AssemblyPath)
[System.Reflection.Assembly]::Load($bytes)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!