Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell: list members of a .net component

I'm trying to build a script that will provide me the listing of the method of a dll from a .net component.

Here's what I've done so far:

Param([String]$path)
if($path.StartsWith("["))
{
$asm = [Reflection.Assembly]::LoadWithPartialName($path)
$asm.GetTypes() | select Name, Namespace | sort Namespace | ft -groupby Namespace
}
else
{
$asm = [Reflection.Assembly]::LoadFile($path)
$asm.GetTypes() | select Name, Namespace | sort Namespace | ft -groupby Namespace
}

So basically the second part of the script (when providing the path of a dll) is working perfectly fine;

Running '.\GetDllMethods.ps1 -path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"' will provide me with all the members of the WinSCP dll.

What I want to achieve with the first part of the script is to get the same result by providing the name of the .net component using something like:

.\GetDllMethods.ps1 -path "[System.IO.StreamWriter]"

To get all the member of the StreamWriter component.

But I'm getting a null exception here.. Any hint ?

like image 239
Marc Avatar asked Oct 10 '14 10:10

Marc


1 Answers

you can use the powershell cmdlet get-member

PS>[system.net.webclient]|get-member  -MemberType method                                                                              


   TypeName : System.RuntimeType                                                                                

Name                           MemberType Definition                                                            
----                           ---------- ----------                                                            
AsType                         Method     type AsType()                                                         
Clone                          Method     System.Object Clone(), System.Object ICloneable.Clone()               

...

we can see there is a GetMethods method, so try :

[system.net.webclient].GetMethods()    
like image 151
Loïc MICHEL Avatar answered Oct 22 '22 04:10

Loïc MICHEL