PowerShell: Calling static and instance methods from PowerShell

Powershell can be used to call both static and instance methods present in your classes. Suppose the dll is present in the GAC, the first thing we need to do is to load the dll. This can be done in two ways:
[System.Reflection.Assembly]::Load("NY.Export, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3796069b4027c3a5")
OR
[System.Reflection.Assembly]::LoadWithPartialName("NY.Export")
If the dll is present at any location in the drive, we can use LoadFile:
[System.Reflection.Assembly]::LoadFile("c:\Test\NY.Export.dll")
Suppose, you have a static method in your class, then it can be called like this:
[NY.Export.SharepointUtility]::TailorContractLibrary($web, $libraryName, $listTemplate)
Where NY.Export is the name of the namespace and SharepointUtility is the name of
the class and TailorContractLibrary is the name of the static method.
Similarly, the instance method can be called by first creating the object of the class
and then calling the method on newly created object:
$obj = New-Object NY.Export.SharepointUtility
$list = $obj.GetContractLibrary($libraryName)
Here GetContractLibrary is the name of instance method in class SharepointUtility

profile for Nadeem Yousuf at SharePoint Stack Exchange, Q&A for SharePoint enthusiasts

+