Methods and strings

Angela Claudio 41 Reputation points
2021-10-26T16:08:56.157+00:00

Hi everyone is not clear to me how to see all the methods and properties of objects and strings. For example with Get Service | Get-member, I can see the object the properties and methods of the Service object. If I do instead get-wmiobject | Get-member returns me error; Same thing for format-table | Get-member and others, ie the get-member does not always work because? How do I know the methods and properties with other commands? Also if I have an invented string "This operating system is" to this string follows the point "." And I can apply methods and properties. Here's here, how can I see a text string all the methods and properties I can use?

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,319 questions
0 comments No comments
{count} votes

Accepted answer
  1. Rich Matheisen 44,416 Reputation points
    2021-10-26T18:40:48.217+00:00

    Get-Member requires an object.

    PS C:\Users\richm> ft | gm
    
    gm : You must specify an object for the Get-Member cmdlet.
    At line:1 char:6
    + ft | gm
    +      ~~
        + CategoryInfo          : CloseError: (:) [Get-Member], InvalidOperationException
        + FullyQualifiedErrorId : NoObjectInGetMember,Microsoft.PowerShell.Commands.GetMemberCommand
    
    PS C:\Users\richm> "x" | ft | gm
    
    
    
       TypeName: Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData
    
    Name                                    MemberType Definition
    ----                                    ---------- ----------
    Equals                                  Method     bool Equals(System.Object obj)
    GetHashCode                             Method     int GetHashCode()
    GetType                                 Method     type GetType()
    ToString                                Method     string ToString()
    ClassId2e4f51ef21dd47e99d3c952918aff9cd Property   string ClassId2e4f51ef21dd47e99d3c952918aff9cd {get;}
    formatEntryInfo                         Property   Microsoft.PowerShell.Commands.Internal.Format.FormatEntryInfo, System.Management.Automation, Version=...
    outOfBand                               Property   bool outOfBand {get;set;}
    writeStream                             Property   Microsoft.PowerShell.Commands.Internal.Format.WriteStreamType, System.Management.Automation, Version=... 
    

    Here's a very simple example of how to see all the methods and properties for a string object:

    "x" | gm * -force
    

    Why not download and work your way through this free PDF? You'll learn a lot about PowerShell. Windows-PowerShell-4

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. MotoX80 31,316 Reputation points
    2021-10-26T16:49:42.427+00:00

    Format-List is a cmdlet, not an object. Use Get-Help to see more information.

    PS C:\> get-help Format-List  
      
    NAME  
        Format-List  
          
    SYNOPSIS  
        Formats the output as a list of properties in which each property appears on a new line.  
          
          
    SYNTAX  
        Format-List [[-Property] <Object[]>] [-DisplayError] [-Expand {CoreOnly | EnumOnly | Both}] [-Force] [-GroupBy <Object>]   
        [-InputObject <PSObject>] [-ShowError] [-View <String>] [<CommonParameters>]  
          
          
    DESCRIPTION  
        The Format-List cmdlet formats the output of a command as a list of properties in which each property is displayed on a separate   
        line. You can use Format-List to format and display all or selected properties of an object as a list (format-list *).  
          
        Because more space is available for each item in a list than in a table, Windows PowerShell displays more properties of the object in   
        the list, and the property values are less likely to be truncated.  
          
      
    RELATED LINKS  
        Online Version: http://go.microsoft.com/fwlink/?LinkId=821774  
        Format-Custom   
        Format-Hex   
        Format-Table   
        Format-Wide   
      
    REMARKS  
        To see the examples, type: "get-help Format-List -examples".  
        For more information, type: "get-help Format-List -detailed".  
        For technical information, type: "get-help Format-List -full".  
        For online help, type: "get-help Format-List -online"  
    

    What tool are you using to write your script? I like to use Powershell_ISE but that is being replaced by VS Code. It expands properties, methods and for cmdlets it shows parameters.

    143887-capture.jpg

    143902-capture2.jpg

    In the view menu, use the commands add on to see more about the parameters for a given cmdlet.

    143837-capture3.jpg

    0 comments No comments

  2. Angela Claudio 41 Reputation points
    2021-10-26T21:17:36.017+00:00

    I answer both: if I do get-service | Get-member, in this case Get-Service is the object and cmdlet right? GET-WMIOBJECT | Get-member, Wmiobject So it's not an object? You have to apologize but I'm a neophyte and I'm learning now. How can I understand that the data is an object? OK Get Service is easy to intuit it to understand that service is a class of objects. But even wmiobject I see him as an object and cmdlet linked to the Get-Verb + Noun.

    I answer Motox80 actually being a neophyte I should use an IDE I am using Powershell Standard version