Get a member and go through .Net in Powershell

I probably don't have an exact name for this question, but I'm just learning powershell, and I'm pretty confused as it is now. I have the following situation and I want to know how to view .NET functions (at the end of this question). For example, I have:

System.DirectoryServices.DirectoryEntry 

I set this to a variable, for example:

 $test = new-object System.DirectoryServices.DirectoryEntry 

If I want to get methods for this, I do:

 $test | gm 

This returns a lot of different names and element types, but I only need the method member, but if I do this:

 $test | gm -membertype method 

I get no results ... however, if I do

 $test.get_children() 

it will display the distinguished name and path ... So my question is why, if it is a method, it now displayed when I called GM -membertype method ??

Also, if I do

 ,$test.get_children() | gm 

I get all kinds of different methods, but if I do

 $test.get_children() | gm 

I get nothing but properties Why doesn't it show methods? I should also note that I was unable to use any of the Membertype methods for ,$test.get_childre() | gm ,$test.get_childre() | gm

It doesn't really matter to me. Can someone explain this and how to determine what I can do with certain .NET functions. Another example might be:

 $domain = [System.DirecotryServices.ActiveDirectory.Domain] 

How can I navigate this path? Therefore, I would suggest that I should use System. → and see what is available, and select DirectoryServices → and see what is available there.

+4
source share
2 answers

I was able to list the methods using the following approach:

 $test = new-object System.DirectoryServices.DirectoryEntry $test.psbase | get-member -force -Type Method 

Without specifying the -Force parameter, you cannot see all the methods you are looking for for this object.

0
source

You can also get methods and all other hidden elements using this method:

 $test | gm -MemberType method -View All -Force 

Enter this on the console for more information:

  help gm -param view 
0
source

Source: https://habr.com/ru/post/1479026/


All Articles