Powershell: list of .net component members

I am trying to create a script that will give me a list of the dll method from the .net component.

Here is what I have 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 to the dll) works 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 specifying the name of the .net component, using something like:

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

To get the entire member of the StreamWriter component.

But I get an empty exception here .. Any hint?

+4
2

, , script .

, :

  • , , ,
  • LoadWithPartialName ,

, :

[Reflection.Assembly]::GetAssembly('assemblyName')

try-catch , /.

+3

powershell 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()               

...

, GetMethods, :

[system.net.webclient].GetMethods()    
+2

All Articles