Why doesn't Get-Member give a full list of all properties and methods.

powershell

Solution

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.

Problem

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.

Original source