powershellmethodsdefinition

Powershell Core Get-Member


Humbling seeking help. Beginner Powershell Core 7.4.2 scriptwriter. In reference to Get-Member results. My background is that I really prefer using Powershell Core's built in documentation rather than connecting to the internet or using an extension in an IDE. Here's an example of what I'm trying to do using just the Powershell Core

Get-Member cmdlet.
Example:
 Get-Member -Name Trim -InputObject system.string[]

   TypeName: System.String
Name MemberType Definition
---- ---------- ----------
Trim Method     string Trim(), string Trim(char trimChar), string Trim(Params char[] trimCha…

My question. How do I get the full definition of Trim Method, used in the example above, beyond the elipses ... ?

Studied the Get-Member documentation


Solution

  • To get a list of the overloaded method definitions for an object, one per line, simply type out the command that you would normally use with the object in question, with the method's name, and simply leave off any arguments or parenthesis. In this case, I'm using quotes to create an instance of a [string] object.

    PS>"".trim
    
    OverloadDefinitions
    -------------------
    string Trim(Params char[] trimChars)
    string Trim()
    
    PS>"".StartsWith
    
    OverloadDefinitions
    -------------------
    bool StartsWith(string value)
    bool StartsWith(string value, System.StringComparison comparisonType)
    bool StartsWith(string value, bool ignoreCase, cultureinfo culture)
    

    You can use this on static methods also.

    PS>[Environment]::SetEnvironmentVariable
    
    OverloadDefinitions
    -------------------
    static void SetEnvironmentVariable(string variable, string value)
    static void SetEnvironmentVariable(string variable, string value, System.EnvironmentVariableTarget target)