Can I access My Custom .NET Class from PowerShell?

为君一笑 提交于 2019-12-30 06:39:13

问题


I have a couple of questions and doubts to regarding PowerShell and .NET Classes.

I am trying to write a class 'foo' that will call Rest web service and perform some tasks. If I deploy the class in GAC then can I call it from PowerShell?


回答1:


Try:

ADD-TYPE -AssemblyName myassemblyname

or

[System.Reflection.Assembly]::LoadWithPartialName("myassemblyname")

to access method/properties of your assembly you can do this:

[myassemblyname]::mymethod()
[myassemblyname]::myproperty



回答2:


You can load your assembly with the Add-Type cmdlet or with System.Reflection.Assembly class and then you can use the New-Object cmdlet to create objects from your assembly classes.



来源:https://stackoverflow.com/questions/9212459/can-i-access-my-custom-net-class-from-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!