question

AngelaClaudio-6862 avatar image
0 Votes"
AngelaClaudio-6862 asked RichMatheisen-8856 commented

Methods and strings

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered

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


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

MotoX80 avatar image
0 Votes"
MotoX80 answered

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



capture.jpg (32.3 KiB)
capture2.jpg (29.5 KiB)
capture3.jpg (75.9 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AngelaClaudio-6862 avatar image
0 Votes"
AngelaClaudio-6862 answered RichMatheisen-8856 commented

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

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

No, the Get-Service cmdlet isn't the object that's piped to Get-Member. The output from Get-Service is sent into the pipeline, and the Get-Member cmdlet acts on the object(s) it retrieves from the pipeline. In this case, the Get-Member will show you the members of the System.ServiceProcess.ServiceController objects emitted by Get-Service.

If you try to use Get-WmiObject without supplying a WMI Class name as a parameter you'll be asked to supply the class:

 get-wmiobject
    
 cmdlet Get-WmiObject at command pipeline position 1
 Supply values for the following parameters:
 Class:

However, if you do this: get-wmiobject -Class Win32_Bios | gm you'll see the members of the object whose type is System.Management.ManagementObject#root\cimv2\Win32_BIOS

If you do as I suggested in my earlier answer, and get that PDF you'll be much more comfortable using PowerShell. The first half of the book will acquaint you with the language. Read each chapter and do the exercises. The second half of the book demonstrates how to apply PowerShell to common administrative tasks (and uses what you learned in the first half).

In my opinion, the ISE used to be worthwhile. But Microsoft is no longer supporting the ISE. You'd do better using VS Code or even Visual Studio as your ISE. Each may take you a while to learn, but the additional features and extensions will make your coding much more productive.

0 Votes 0 ·