Export (0) Print
Expand All
Collapse the table of content
Expand the table of content
Expand Minimize

Get-Member

Updated: August 9, 2015

Get-Member

Gets the properties and methods of objects.

Aliases

The following abbreviations are aliases for this cmdlet: 

  • gm

Syntax

Parameter Set: Default
Get-Member [[-Name] <String[]> ] [-Force] [-InputObject <PSObject> ] [-MemberType <PSMemberTypes> {AliasProperty | CodeProperty | Property | NoteProperty | ScriptProperty | Properties | PropertySet | Method | CodeMethod | ScriptMethod | Methods | ParameterizedProperty | MemberSet | Event | Dynamic | All} ] [-Static] [-View <PSMemberViewTypes> {Extended | Adapted | Base | All} ] [ <CommonParameters>]




Detailed Description

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, use the MemberType parameter.

Parameters

-Force

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.

The following list describes the properties that are added when you use the Force parameter:

-- PSBase: The original properties of the .NET Framework object without extension or adaptation. These are the properties defined for the object class and listed in MSDN.

-- PSAdapted. The properties and methods defined in the Windows PowerShell extended type system.

-- PSExtended. The properties and methods that were added in the Types.ps1xml files or by using the Add-Member cmdlet.

-- PSObject. The adapter that converts the base object to a Windows PowerShell PSObject object.

-- PSTypeNames. A list of object types that describe the object, in order of specificity. When formatting the object, Windows PowerShell searches for the types in the Format.ps1xml files in the Windows PowerShell installation directory ($pshome). It uses the formatting definition for the first type that it finds.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-InputObject<PSObject>

Specifies the object whose members are retrieved.

Using the InputObject parameter is not the same as piping an object to Get-Member. The differences are as follows:

-- When you pipe a collection of objects to Get-Member, Get-Member gets the members of the individual objects in the collection, such as the properties of each string in an array of strings.

-- When you use InputObject to submit a collection of objects, Get-Member gets the members of the collection, such as the properties of the array in an array of strings.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

true (ByValue)

Accept Wildcard Characters?

false

-MemberType<PSMemberTypes>

Specifies the member type that this cmdlet gets. The default is All.

The acceptable values for this parameter are:

-- AliasProperty
-- CodeProperty
-- Property
-- NoteProperty
-- ScriptProperty
-- Properties
-- PropertySet
-- Method
-- CodeMethod
-- ScriptMethod
-- Methods
-- ParameterizedProperty
-- MemberSet
-- Event
-- Dynamic
-- All

For information about these values, see PSMemberTypes Enumeration" (https://msdn.microsoft.com/en-us/library/system.management.automation.psmembertypes(v=vs.85).aspx ) in MSDN.

Not all objects have every type of member. If you specify a member type that the object does not have, Windows PowerShell returns a null value.

To get related types of members, such as all extended members, use the View parameter. If you use the MemberType parameter with the Static or View parameters, Get-Member gets the members that belong to both sets.


Aliases

Type

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Name<String[]>

Specifies the names of one or more properties or methods of the object. Get-Member gets only the specified properties and methods.

If you use the Name parameter with the MemberType, View, or Static parameter, Get-Member gets only the members that satisfy the criteria of all parameters.

To get a static member by name, use the Static parameter with the Name parameter.


Aliases

none

Required?

false

Position?

1

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Static

Indicates that this cmdlet gets only the static properties and methods of the object.

Static properties and methods are defined on the class of objects, not on any particular instance of the class.

If you use the Static parameter with the View parameter, the View parameter is ignored. If you use the Static parameter with the MemberType parameter, Get-Member gets only the members that belong to both sets.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-View<PSMemberViewTypes>

Specifies that this cmdlet gets only particular types properties and methods. Specify one or more of the values. The default is Adapted, Extended.

Valid values are:

-- Base. Gets only the original properties and methods of the .NET Framework object (without extension or adaptation).

-- Adapted. Gets only the properties and methods defined in the Windows PowerShell extended type system.

-- Extended. Gets only the properties and methods that were added in the Types.ps1xml files or by using the Add-Member cmdlet.

-- All. Gets the members in the Base, Adapted, and Extended views.

The View parameter determines the members retrieved, not just the display of those members.

To get particular member types, such as script properties, use the MemberType parameter. If you use the MemberType and View parameters in the same command, Get-Member gets the members that belong to both sets. If you use the Static and View parameters in the same command, the View parameter is ignored.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

<CommonParameters>

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see    about_CommonParameters.

Inputs

The input type is the type of the objects that you can pipe to the cmdlet.

  • System.Management.Automation.PSObject

    You can pipe any object to Get-Member.


Outputs

The output type is the type of the objects that the cmdlet emits.

  • Microsoft.PowerShell.Commands.MemberDefinition

    Get-Member returns an object for each property or method that its gets.


Notes

  • You can get information about a collection object either by using the InputObject parameter or by piping the object, preceded by a comma, to Get-Member.

    You can use the $This automatic variable in script blocks that define the values of new properties and methods. The $This variable refers to the instance of the object to which the properties and methods are being added. For more information about the $This variable, see about_Automatic_Variables.

Examples

Example 1: Get the members of process objects

This command displays the properties and methods of the process objects (System.ServiceProcess.ServiceController) that are generated by the Get-Service cmdlet.

The command uses the pipeline operator (|) to send the output of a Get-Service command to Get-Member.

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.


PS C:\> Get-Service | Get-Member

Example 2: Get members of service objects

This example gets all of the members (properties and methods) of the service objects (System.ServiceProcess.ServiceController) retrieved by the Get-Service cmdlet, including the intrinsic members, such as PSBase and PSObject, and the get_ and set_ methods.

The first command uses the Get-Service cmdlet to get objects that represent the services on the system. It uses a pipeline operator (|) to pass the service objects to the Get-Member cmdlet.

The Get-Member command uses the Force parameter to add the intrinsic members and compiler-generated members of the objects to the display. Get-Member gets these members, but it hides them by default.

You can use these properties and methods in the same way that you would use an adapted method of the object. The second command shows how to display the value of the PSBase property of the Schedule service.


PS C:\> Get-Service | Get-Member -Force
PS C:\> (Get-Service -Schedule).PSBase

Example 3: Get extended members of service objects

This command gets the methods and properties of service objects that were extended by using the Types.ps1xml file or the Add-Member cmdlet.

The Get-Member command uses the View parameter to get only the extended members of the service objects. In this case, the extended member is the Name property, which is an alias property of the ServiceName property.


PS C:\> Get-Service| Get-Member -View Extended

Example 4: Get script properties of event log objects

This command gets the script properties of event log objects in the System log in Event Viewer.

The command uses the MemberType parameter to get only objects with a value of ScriptProperty for their MemberType property.

The command returns the EventID property of the EventLog object.


PS C:\> Get-EventLog -Log System | Get-Member -MemberType ScriptProperty

Example 5: Get objects with a specified property

This command gets objects that have a MachineName property from a list of cmdlets.

The first command stores the names of several cmdlets in the $A variable.

The second command uses a ForEach statement to invoke each command, send the results to Get-Member, and limit the results from Get-Member to members that have the name MachineName.

The results show that only process objects (System.Diagnostics.Process) and service objects (System.ServiceProcess.ServiceController) have a MachineName property.


PS C:\> $A = "Get-Process", "Get-Service", "Get-Culture", "Get-PSDrive", "Get-ExecutionPolicy"
PS C:\> ForEach ($Cmdlet in $A) {Invoke-Command $Cmdlet | Get-Member -Name MachineName}

Example 6: Get members for an array

This example demonstrates how to find the properties and methods of an array of objects when you have only one object of the given type.

Because the goal of the command is to find the properties of an array, the first command uses the InputObject parameter. It uses the at symbol (@) to indicate an array. In this case, the array contains only one object, the integer 1.

The third command uses the Get-Member cmdlet to get the properties and methods of an array of integers, and the command saves them in the $A variable.

The fourth command uses the Count property of the array to find the number of objects in the $A variable.


PS C:\> $A = Get-Member - InputObject @(1)
PS C:\> $A.Count
PS C:\> $A = Get-Member -InputObject 1,2,3
PS C:\> $A.Count

Example 7: Determine which object properties you can set

This example shows how to determine which properties of an object can be changed. The example uses a file, but you can use this command format to find the changeable properties of any object in Windows PowerShell.

The first command uses the Get-Item cmdlet to get a text file, and then it saves the file object in the $File variable.

The second command gets all of the changeable properties of the file object in the $File variable and displays the names of the properties in a table.

The third command gets the changeable properties of all objects in your Windows PowerShell session.


PS C:\> $File = Get-Item c:\test\textFile.txt
PS C:\> $File.psobject.properties | Where-Object {$_.issettable} | Format-Table -Property name
PS C:\> [appdomain]::CurrentDomain.GetAssemblies() | ForEach-Object { $_.getexportedtypes() } | ForEach-Object {$_.getproperties() | Where-Object {$_.canwrite }} | Select-Object reflectedtype, name

Example 8: Get members of each item in a collection

This example shows how the InputObject parameter works in the Get-Member cmdlet. When you use the InputObject parameter to get the members of a collection, Get-Member gets the members of the collection. When you pipe a collection of objects to Get-Member, Get-Member gets the members of each item in the collection.

The first command gets the services on the local computer and saves the services in the $S variable.

The second command pipes the $S variable to the Get-Member cmdlet. Get-Member gets the types of each member of $S and the members of that type. In this case, it gets ServiceController objects and lists the members, such as RequiredServices and Close.

The third command uses the InputObject parameter of Get-Member to submit the $S variable. Get-Member gets the type (System.Object[]) and the members of the collection (or array) of ServiceController objects, such as Count and Clone.


PS C:\> $S = Get-Service
PS C:\> $S | Get-Member
PS C:\> Get-Member -InputObject $S

Related topics

Community Additions

ADD
Show:
© 2016 Microsoft