I recently discovered that I can access a property for something that isn't listed when running it through get-member.
Here is an example, which I will demonstrate by using a custom psobject.
First, I'll create the hashtable (which I will later use to create the psobject):
$MyHashtable = @{'column1'="aaa";
'column2'="bbb";
'column3'="ccc"
}
Now I create my psobject:
PS C:\> $MyNewObject = New-Object -TypeName PSObject -Property $MyHashtable
Now if I run this new object through get-member, it shows:
PS C:\> $MyNewObject | Get-Member
TypeName: System.Management.Automation.PSCustomObject
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
column1 NoteProperty System.String column1=aaa
column2 NoteProperty System.String column2=bbb
column3 NoteProperty System.String column3=ccc
So far, so good (although I suspect that a property called "PSObject" is missing from the above list, which I am about to demonstrate now).
However if I now do:
PS C:\> $MyNewObject.PSObject
Members : {System.String column1=aaa, System.String column2=bbb, System.String column3=ccc, string ToString()...}
Properties : {System.String column1=aaa, System.String column2=bbb, System.String column3=ccc}
Methods : {string ToString(), bool Equals(System.Object obj), int GetHashCode(), type GetType()}
ImmediateBaseObject :
BaseObject :
TypeNames : {System.Management.Automation.PSCustomObject, System.Object}
This worked! How is that possible since "PSObject" wasn't listed as a property when we passed the object through Get-Member.
Hope someone can help.
To display all the properties and methods available for the get-service cmdlet you need to pipeline Get-Member (alias gm). MemberType 'Property' is to display the specific property like machinename, servicename, etc.
The Get-Member command lets you list only members that are properties. There are several forms of properties. The cmdlet displays properties of any type if we set the MemberType parameter to the value Properties. The resulting list is still very long, but a bit more manageable: PowerShell Copy.
To discover information about an object (members), you can use the Get-Member cmdlet. The Get-Member cmdlet is a handy command that allows you find available properties, methods and so on for any object in PowerShell.
To get only certain types of members, such as NoteProperties , use the MemberType parameter. Adds the intrinsic members (PSBase, PSAdapted, PSObject, PSTypeNames) and the compiler-generated get_ and set_ methods to the display. By default, Get-Member gets these properties in all views other than Base and Adapted, but it does not display them.
PowerShell provides Get-Member cmdlet to know the list of members of the objects. The Get-Member cmdlet. Get-Member cmdlet is used to get the members of the objects; the methods, properties, events etc, associated with the objects. It always need an input to get the members.
The Get-Member cmdlet gets the members, the properties and methods, of objects. To specify the object, use the InputObject parameter or pipe an object to Get-Member. To get information about static members, the members of the class, not of the instance, use the Static parameter. To get only certain types of members, such as NoteProperties, ...
Because the Get-Member part of the command does not have any parameters, it uses all of the default values. As such, it gets all member types, but it does not get static members and does not display intrinsic members.
Use Get-Member -Force to see all members
-Force [SwitchParameter] Adds the intrinsic members (PSBase, PSAdapted, PSObject, PSTypeNames) and the compiler-generated get_ and set_ methods to the display. By default, Get-Member gets these properties in all views other than "Base" and "Adapted," but it does not display them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With