6

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?

Mitul
  • 9,504
  • 4
  • 40
  • 59

2 Answers2

12

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
CB.
  • 56,179
  • 8
  • 151
  • 155
3

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.

Shay Levy
  • 114,369
  • 30
  • 175
  • 198
  • And this way I can access all the methods of that object in PowerShell and automate things. Cool. – Mitul Feb 09 '12 at 14:36
  • 1
    yes, take a look at the code examples of Add-Type, http://technet.microsoft.com/en-us/library/dd315241.aspx – Shay Levy Feb 09 '12 at 14:50