How to find PowerShell Static Classes and Methods?

后端 未结 4 383
忘掉有多难
忘掉有多难 2021-01-03 14:34

How can I find what Static Classes and Methods there is available in PowerShell 2.0?

相关标签:
4条回答
  • 2021-01-03 15:15

    Mr driis, you are the man !!! Totally made my day !

    I just took the liberty to modify it a little bit so it returns the whole list without duplicates:

    PS C:\Users\Administrator> [AppDomain]::CurrentDomain.GetAssemblies() | foreach { $_.GetTypes() } | foreach { $_.GetMethods() } | where { $_.IsStatic } | select DeclaringType | Out-File assemblies.txt
    

    and then read the assemblies.txt file but only get unique rows :

    cat .\assemblies.txt Get-Unique
    
    0 讨论(0)
  • 2021-01-03 15:26

    You can use any .NET types and their static methods from PowerShell. To enumerate all that are currently loaded into your AppDomain, you can do:

     [AppDomain]::CurrentDomain.GetAssemblies() | foreach { $_.GetTypes() } | foreach { $_.GetMethods() } | where { $_.IsStatic } | select DeclaringType, Name | format-table
    

    Remember, you are not limited to static methods, you can also instantiate the types using new-object and call instance methods. You can use get-member on an instance to get the methods on a type.

    Also, if you want to list your available CmdLets, just invoke:

    Get-Command
    
    0 讨论(0)
  • 2021-01-03 15:29

    To get the static members of a type or object, pipe it to Get-Member and specify the Static switch:

    [math] | Get-Member -Static
    
    0 讨论(0)
  • 2021-01-03 15:32

    You have the classes ( static or otherwise ) from .NET framework.

    Once you have the class, you can use Get-Member:

    [Environment] | Get-Member
    

    PS: "Windows PowerShell Cookbook" by Lee Holmes has an Appendix which lists some useful classes, from Powershell / SysAdmin point of view. That list( and the book) is very useful.

    0 讨论(0)
提交回复
热议问题