Question:
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:
1 2 3 4 5 6 7 8 9 10 11 12 |
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 ?
Answer:
you can use the powershell cmdlet get-member
1 2 3 4 5 6 7 8 9 10 |
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 :
1 2 |
[system.net.webclient].GetMethods() |