powershell get more information on object property?

Discussion in 'Programming & Software Development' started by Multiplexer, Jul 15, 2020.

  1. Multiplexer

    Multiplexer Member

    Feb 26, 2002
    I want to know how to get more information on object property. I pipe Get-Member then I dont know what to do with the Method or Property.

    For example "get-vm | Get-Member"

    PS C:\Users\> get-vm | Get-Member                                                                                                                                                                                                                                   
       TypeName: VMware.VimAutomation.ViCore.Impl.V1.VM.UniversalVirtualMachineImpl
    Name                    MemberType Definition
    ----                    ---------- ----------
    ConvertToVersion        Method     T VersionedObjectInterop.ConvertToVersion[T]()
    Equals                  Method     bool Equals(System.Object obj)
    GetClient               Method     VMware.VimAutomation.ViCore.Interop.V1.VIAutomation VIObjectCoreInterop.GetClient()
    GetConnectionParameters Method     VMware.VimAutomation.ViCore.Interop.V1.VM.RemoteConsoleVMParams RemoteConsoleVMInterop.GetConnectionParameters()
    GetHashCode             Method     int GetHashCode()
    GetType                 Method     type GetType()
    IsConvertableTo         Method     bool VersionedObjectInterop.IsConvertableTo(type type)
    LockUpdates             Method     void ExtensionData.LockUpdates()
    ObtainExportLease       Method     VMware.Vim.ManagedObjectReference ObtainExportLease.ObtainExportLease()
    ToString                Method     string ToString()
    UnlockUpdates           Method     void ExtensionData.UnlockUpdates()
    CoresPerSocket          Property   int CoresPerSocket {get;}
    CreateDate              Property   System.Nullable[datetime] CreateDate {get;}
    CustomFields            Property   System.Collections.Generic.IDictionary[string,string] CustomFields {get;}
    DatastoreIdList         Property   string[] DatastoreIdList {get;}
    DrsAutomationLevel      Property   System.Nullable[VMware.VimAutomation.ViCore.Types.V1.Cluster.DrsAutomationLevel] DrsAutomationLevel {get;}
    ExtensionData           Property   System.Object ExtensionData {get;}
    Folder                  Property   VMware.VimAutomation.ViCore.Types.V1.Inventory.Folder Folder {get;}
    FolderId                Property   string FolderId {get;}
    Guest                   Property   VMware.VimAutomation.ViCore.Types.V1.VM.Guest.VMGuest Guest {get;}
    GuestId                 Property   string GuestId {get;}
    HAIsolationResponse     Property   System.Nullable[VMware.VimAutomation.ViCore.Types.V1.Cluster.HAIsolationResponse] HAIsolationResponse {get;}
    HardwareVersion         Property   string HardwareVersion {get;}
    HARestartPriority       Property   System.Nullable[VMware.VimAutomation.ViCore.Types.V1.Cluster.HARestartPriority] HARestartPriority {get;}
    Id                      Property   string Id {get;}
    MemoryGB                Property   decimal MemoryGB {get;}
    MemoryMB                Property   decimal MemoryMB {get;}
    Name                    Property   string Name {get;}
    Notes                   Property   string Notes {get;}
    NumCpu                  Property   int NumCpu {get;}
    PersistentId            Property   string PersistentId {get;}
    PowerState              Property   VMware.VimAutomation.ViCore.Types.V1.Inventory.PowerState PowerState {get;}
    ProvisionedSpaceGB      Property   decimal ProvisionedSpaceGB {get;}
    ResourcePool            Property   VMware.VimAutomation.ViCore.Types.V1.Inventory.ResourcePool ResourcePool {get;}
    ResourcePoolId          Property   string ResourcePoolId {get;}
    Uid                     Property   string Uid {get;}
    UsedSpaceGB             Property   decimal UsedSpaceGB {get;}
    VApp                    Property   VMware.VimAutomation.ViCore.Types.V1.Inventory.VApp VApp {get;}
    Version                 Property   VMware.VimAutomation.ViCore.Types.V1.VM.VMVersion Version {get;}
    VMHost                  Property   VMware.VimAutomation.ViCore.Types.V1.Inventory.VMHost VMHost {get;}
    VMHostId                Property   string VMHostId {get;}
    VMResourceConfiguration Property   VMware.VimAutomation.ViCore.Types.V1.VM.VMResourceConfiguration VMResourceConfiguration {get;}
    VMSwapfilePolicy        Property   System.Nullable[VMware.VimAutomation.ViCore.Types.V1.VMSwapfilePolicy] VMSwapfilePolicy {get;}
    I would have no idea what I can do with ExtensionData until I google "PowerCLI VN hotplug" to find below

    Get-VM -name dc1 | Select Name, @{N="CpuHotAddEnabled";E={$_.ExtensionData.Config.CpuHotAddEnabled}}, @{N="MemoryHotAddEnabled";E={$_.ExtensionData.Config.MemoryHotAddEnabled}}

    Want to know Method as well.
  2. Yehat

    Yehat Member

    Aug 4, 2002
    Some short suggestions:
    • Get-Member works on objects so you could just invoke it again on the returned objects to get the subsequent available properties/methods
    • When you call Methods without brackets, powershell can show you the available method signature(s) (multiple signatures can be returned if there's overloaded methods)
    Very Long version:
    I don't have PowerCLI extensions but here's an example with Get-PSHostProcessInfo (note this example is very trivial but I hope it illustrates the intent)

    Get-PSHostProcessInfo in a powershell window for me shows the following (i.e. for the purpose of this example assume it just returns information about one process):

    ProcessName ProcessId AppDomainName    MainWindowTitle
    ----------- --------- -------------    ---------------
    powershell      16160 DefaultAppDomain Windows PowerShell
    Again purely for example purposes I could use the same kind of syntax in your post to do:
    Which returns:
    ProcessName     : powershell
    ProcessId       : 16160
    AppDomainName   : DefaultAppDomain
    MainWindowTitle : Windows PowerShell
    IsTypePublic    : True
    TypeName        : PSHostProcessInfo
    The specific returned values themselves aren't important, but my understanding is your post is asking: how can we know that for a command like the above (without using the API docs) that it returns:
    1. Properties (in this case) called Processname, ProcessId, AppDomainName, MainWindowTitle, and what properties/methods those returned objects have ?
    2. Methods, for example where one was called GetType() ?
      • (a) What's the methods signature / how to know GetType() returns an object ?
      • (b) For the objects (in this case returned by GetType() but it could apply to any objects) how to know they had properties available (in this case called "IsPublic" and "Name").
    So for (#1) By piping it to Get-Member (your post already covers this):
    Get-PSHostProcessInfo | Get-Member
       TypeName: Microsoft.PowerShell.Commands.PSHostProcessInfo
    Name            MemberType Definition
    ----            ---------- ----------
    Equals          Method     bool Equals(System.Object obj)
    GetHashCode     Method     int GetHashCode()
    GetType         Method     type GetType()
    ToString        Method     string ToString()
    AppDomainName   Property   string AppDomainName {get;}
    MainWindowTitle Property   string MainWindowTitle {get;}
    ProcessId       Property   int ProcessId {get;}
    ProcessName     Property   string ProcessName {get;}
    There are the 4 Properties which resolve to string/int types, and we can query these directly:

    Get-PSHostProcessInfo | Select ProcessName, ProcessId, AppDomainName, MainWindowTitle

    If we wanted to know what methods/properties a particular object relating to a Property above had, we can pipe that to Get-Member.
    (Get-PSHostProcessInfo).ProcessName | Get-Member

    In this case ProcessName was just a string, so the above is just going to list the available methods/properties associated with string. Where doing this would be more beneficial (like in your example with ExtensionData) is if the object we were piping was a more complex type. And that will be covered in the example for (2b).

    For (2) Regarding methods, Get-PSHostProcessInfo had 4 methods available above.
    If we want to know what method signatures are available, we can call a method without brackets () at the end of the method name.


    type GetType()
    In this case there is just one method which returns something called "type" and takes no parameters. If there were additional overloaded methods it would return the list of those method signatures.

    (2b) So now we know the method GetType() returns something called "type" but what properties/methods does that entity have ?

    You could call the method (i.e. add the brackets to the end of GetType()):
    IsPublic IsSerial Name                                     BaseType
    -------- -------- ----                                     --------
    True     False    PSHostProcessInfo                        System.Object
    And in this case it prints some values.
    Instead if we piped the object GetType() returns to Get-Member again:

    (Get-PSHostProcessInfo).GetType() | Get-Member
       TypeName: System.RuntimeType
    Name                           MemberType Definition
    ----                           ---------- ----------
    AsType                         Method     type AsType()
    Clone                          Method     System.Object Clone(), System.Object ICloneable.Clone()
    Equals                         Method     bool Equals(System.Object obj), bool Equals(type o), bool _MemberInfo.Equa...
    FindInterfaces                 Method     type[] FindInterfaces(System.Reflection.TypeFilter filter, System.Object f...
    FindMembers                    Method     System.Reflection.MemberInfo[] FindMembers(System.Reflection.MemberTypes m...
    GetArrayRank                   Method     int GetArrayRank(), int _Type.GetArrayRank()
    GetConstructor                 Method     System.Reflection.ConstructorInfo GetConstructor(System.Reflection.Binding...
    GetConstructors                Method     System.Reflection.ConstructorInfo[] GetConstructors(System.Reflection.Bind...
    GetCustomAttributes            Method     System.Object[] GetCustomAttributes(bool inherit), System.Object[] GetCust...
    GetCustomAttributesData        Method     System.Collections.Generic.IList[System.Reflection.CustomAttributeData] Ge...
    GetDeclaredEvent               Method     System.Reflection.EventInfo GetDeclaredEvent(string name)
    GetDeclaredField               Method     System.Reflection.FieldInfo GetDeclaredField(string name)
    GetDeclaredMethod              Method     System.Reflection.MethodInfo GetDeclaredMethod(string name)
    GetDeclaredMethods             Method     System.Collections.Generic.IEnumerable[System.Reflection.MethodInfo] GetDe...
    GetDeclaredNestedType          Method     System.Reflection.TypeInfo GetDeclaredNestedType(string name)
    GetDeclaredProperty            Method     System.Reflection.PropertyInfo GetDeclaredProperty(string name)
    GetDefaultMembers              Method     System.Reflection.MemberInfo[] GetDefaultMembers(), System.Reflection.Memb...
    GetElementType                 Method     type GetElementType(), type _Type.GetElementType()
    GetEnumName                    Method     string GetEnumName(System.Object value)
    GetEnumNames                   Method     string[] GetEnumNames()
    GetEnumUnderlyingType          Method     type GetEnumUnderlyingType()
    GetEnumValues                  Method     array GetEnumValues()
    GetEvent                       Method     System.Reflection.EventInfo GetEvent(string name, System.Reflection.Bindin...
    GetEvents                      Method     System.Reflection.EventInfo[] GetEvents(System.Reflection.BindingFlags bin...
    GetField                       Method     System.Reflection.FieldInfo GetField(string name, System.Reflection.Bindin...
    GetFields                      Method     System.Reflection.FieldInfo[] GetFields(System.Reflection.BindingFlags bin...
    GetGenericArguments            Method     type[] GetGenericArguments()
    GetGenericParameterConstraints Method     type[] GetGenericParameterConstraints()
    GetGenericTypeDefinition       Method     type GetGenericTypeDefinition()
    GetHashCode                    Method     int GetHashCode(), int _MemberInfo.GetHashCode(), int _Type.GetHashCode()
    GetIDsOfNames                  Method     void _MemberInfo.GetIDsOfNames([ref] guid riid, System.IntPtr rgszNames, u...
    GetInterface                   Method     type GetInterface(string fullname, bool ignoreCase), type GetInterface(str...
    GetInterfaceMap                Method     System.Reflection.InterfaceMapping GetInterfaceMap(type ifaceType), System...
    GetInterfaces                  Method     type[] GetInterfaces(), type[] _Type.GetInterfaces()
    GetMember                      Method     System.Reflection.MemberInfo[] GetMember(string name, System.Reflection.Me...
    GetMembers                     Method     System.Reflection.MemberInfo[] GetMembers(System.Reflection.BindingFlags b...
    GetMethod                      Method     System.Reflection.MethodInfo GetMethod(string name, System.Reflection.Bind...
    GetMethods                     Method     System.Reflection.MethodInfo[] GetMethods(System.Reflection.BindingFlags b...
    GetNestedType                  Method     type GetNestedType(string fullname, System.Reflection.BindingFlags binding...
    GetNestedTypes                 Method     type[] GetNestedTypes(System.Reflection.BindingFlags bindingAttr), type[] ...
    GetObjectData                  Method     void GetObjectData(System.Runtime.Serialization.SerializationInfo info, Sy...
    GetProperties                  Method     System.Reflection.PropertyInfo[] GetProperties(System.Reflection.BindingFl...
    GetProperty                    Method     System.Reflection.PropertyInfo GetProperty(string name, System.Reflection....
    GetType                        Method     type GetType(), type _MemberInfo.GetType(), type _Type.GetType()
    GetTypeInfo                    Method     void _MemberInfo.GetTypeInfo(uint32 iTInfo, uint32 lcid, System.IntPtr ppT...
    GetTypeInfoCount               Method     void _MemberInfo.GetTypeInfoCount([ref] uint32 pcTInfo), void _Type.GetTyp...
    Invoke                         Method     void _MemberInfo.Invoke(uint32 dispIdMember, [ref] guid riid, uint32 lcid,...
    InvokeMember                   Method     System.Object InvokeMember(string name, System.Reflection.BindingFlags bin...
    IsAssignableFrom               Method     bool IsAssignableFrom(System.Reflection.TypeInfo typeInfo), bool IsAssigna...
    IsDefined                      Method     bool IsDefined(type attributeType, bool inherit), bool ICustomAttributePro...
    IsEnumDefined                  Method     bool IsEnumDefined(System.Object value)
    IsEquivalentTo                 Method     bool IsEquivalentTo(type other)
    IsInstanceOfType               Method     bool IsInstanceOfType(System.Object o), bool _Type.IsInstanceOfType(System...
    IsSubclassOf                   Method     bool IsSubclassOf(type type), bool _Type.IsSubclassOf(type c)
    MakeArrayType                  Method     type MakeArrayType(), type MakeArrayType(int rank)
    MakeByRefType                  Method     type MakeByRefType()
    MakeGenericType                Method     type MakeGenericType(Params type[] instantiation)
    MakePointerType                Method     type MakePointerType()
    ToString                       Method     string ToString(), string _MemberInfo.ToString(), string _Type.ToString()
    Assembly                       Property   System.Reflection.Assembly Assembly {get;}
    AssemblyQualifiedName          Property   string AssemblyQualifiedName {get;}
    Attributes                     Property   System.Reflection.TypeAttributes Attributes {get;}
    BaseType                       Property   type BaseType {get;}
    ContainsGenericParameters      Property   bool ContainsGenericParameters {get;}
    CustomAttributes               Property   System.Collections.Generic.IEnumerable[System.Reflection.CustomAttributeDa...
    DeclaredConstructors           Property   System.Collections.Generic.IEnumerable[System.Reflection.ConstructorInfo] ...
    DeclaredEvents                 Property   System.Collections.Generic.IEnumerable[System.Reflection.EventInfo] Declar...
    DeclaredFields                 Property   System.Collections.Generic.IEnumerable[System.Reflection.FieldInfo] Declar...
    DeclaredMembers                Property   System.Collections.Generic.IEnumerable[System.Reflection.MemberInfo] Decla...
    DeclaredMethods                Property   System.Collections.Generic.IEnumerable[System.Reflection.MethodInfo] Decla...
    DeclaredNestedTypes            Property   System.Collections.Generic.IEnumerable[System.Reflection.TypeInfo] Declare...
    DeclaredProperties             Property   System.Collections.Generic.IEnumerable[System.Reflection.PropertyInfo] Dec...
    DeclaringMethod                Property   System.Reflection.MethodBase DeclaringMethod {get;}
    DeclaringType                  Property   type DeclaringType {get;}
    FullName                       Property   string FullName {get;}
    GenericParameterAttributes     Property   System.Reflection.GenericParameterAttributes GenericParameterAttributes {g...
    GenericParameterPosition       Property   int GenericParameterPosition {get;}
    GenericTypeArguments           Property   type[] GenericTypeArguments {get;}
    GenericTypeParameters          Property   type[] GenericTypeParameters {get;}
    GUID                           Property   guid GUID {get;}
    HasElementType                 Property   bool HasElementType {get;}
    ImplementedInterfaces          Property   System.Collections.Generic.IEnumerable[type] ImplementedInterfaces {get;}
    IsAbstract                     Property   bool IsAbstract {get;}
    IsAnsiClass                    Property   bool IsAnsiClass {get;}
    IsArray                        Property   bool IsArray {get;}
    IsAutoClass                    Property   bool IsAutoClass {get;}
    IsAutoLayout                   Property   bool IsAutoLayout {get;}
    IsByRef                        Property   bool IsByRef {get;}
    IsClass                        Property   bool IsClass {get;}
    IsCOMObject                    Property   bool IsCOMObject {get;}
    IsConstructedGenericType       Property   bool IsConstructedGenericType {get;}
    IsContextful                   Property   bool IsContextful {get;}
    IsEnum                         Property   bool IsEnum {get;}
    IsExplicitLayout               Property   bool IsExplicitLayout {get;}
    IsGenericParameter             Property   bool IsGenericParameter {get;}
    IsGenericType                  Property   bool IsGenericType {get;}
    IsGenericTypeDefinition        Property   bool IsGenericTypeDefinition {get;}
    IsImport                       Property   bool IsImport {get;}
    IsInterface                    Property   bool IsInterface {get;}
    IsLayoutSequential             Property   bool IsLayoutSequential {get;}
    IsMarshalByRef                 Property   bool IsMarshalByRef {get;}
    IsNested                       Property   bool IsNested {get;}
    IsNestedAssembly               Property   bool IsNestedAssembly {get;}
    IsNestedFamANDAssem            Property   bool IsNestedFamANDAssem {get;}
    IsNestedFamily                 Property   bool IsNestedFamily {get;}
    IsNestedFamORAssem             Property   bool IsNestedFamORAssem {get;}
    IsNestedPrivate                Property   bool IsNestedPrivate {get;}
    IsNestedPublic                 Property   bool IsNestedPublic {get;}
    IsNotPublic                    Property   bool IsNotPublic {get;}
    IsPointer                      Property   bool IsPointer {get;}
    IsPrimitive                    Property   bool IsPrimitive {get;}
    IsPublic                       Property   bool IsPublic {get;}
    IsSealed                       Property   bool IsSealed {get;}
    IsSecurityCritical             Property   bool IsSecurityCritical {get;}
    IsSecuritySafeCritical         Property   bool IsSecuritySafeCritical {get;}
    IsSecurityTransparent          Property   bool IsSecurityTransparent {get;}
    IsSerializable                 Property   bool IsSerializable {get;}
    IsSpecialName                  Property   bool IsSpecialName {get;}
    IsUnicodeClass                 Property   bool IsUnicodeClass {get;}
    IsValueType                    Property   bool IsValueType {get;}
    IsVisible                      Property   bool IsVisible {get;}
    MemberType                     Property   System.Reflection.MemberTypes MemberType {get;}
    MetadataToken                  Property   int MetadataToken {get;}
    Module                         Property   System.Reflection.Module Module {get;}
    Name                           Property   string Name {get;}
    Namespace                      Property   string Namespace {get;}
    ReflectedType                  Property   type ReflectedType {get;}
    StructLayoutAttribute          Property   System.Runtime.InteropServices.StructLayoutAttribute StructLayoutAttribute...
    TypeHandle                     Property   System.RuntimeTypeHandle TypeHandle {get;}
    TypeInitializer                Property   System.Reflection.ConstructorInfo TypeInitializer {get;}
    UnderlyingSystemType           Property   type UnderlyingSystemType {get;}
    We can then see that GetType() returns an object which gave access to properties including "IsPublic" and "Name".

    In summary:
    • We know that a command (Get-PSHostProcessInfo) returned an object with properties and methods by piping it to Get-Member
    • And that for a given method we were able to get its signature (including that it returned an object) by invoking the method without brackets
    • And for an object returned, we piped that to Get-Member again to determine what properties/methods it had.
    We could just rinse repeat the above to find further properties/methods. I think that's something like what you were after?

    Just for completeness, by default Get-Member doesn't display all members which are available (for example static members are not shown by default) but these (amongst other options) are catered for via documented parameters https://docs.microsoft.com/en-us/po...wershell.utility/get-member?view=powershell-7
    Last edited: Jul 20, 2020
    FerrisXB9R likes this.
  3. OP

    Multiplexer Member

    Feb 26, 2002
    Thanks Yehat, that is a lot of information, I will take the time to read it.

Share This Page