CmdID / PowerShell / Cmdlets / Get
Get-Member
Gets the properties and methods of objects. PowerShell reference
From the PowerShell reference
6 parameters
Alias gm
What it does
Gets the properties and methods of objects. 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. Get-Member returns a list of members that's sorted alphabetically. Methods are listed first, followed by the properties.
Get-Member [-InputObject <PSObject>] [[-Name] <String[]>] [-MemberType <PSMemberTypes>] [-View <PSMemberViewTypes>] [-Static] [-Force] [<CommonParameters>]
Get the members of process objects
Get-Service | Get-MemberIdentifyGet members of service objects
Get-Service | Get-Member -Force
(Get-Service Schedule).psbaseIdentifyGet extended members of service objects
Get-Service | Get-Member -View ExtendedIdentifyGet script properties of event log objects
Get-WinEvent -LogName System -MaxEvents 1 | Get-Member -MemberType NotePropertyIdentifyTrips 1 Sigma rule: mediumEventLog Query Requests By Builtin Utilities by Ali Alwashali, Nasreddine Bencherchali (Nextron Systems)
Get objects with a specified property
$list = "Get-Process", "Get-Service", "Get-Culture", "Get-PSDrive", "Get-ExecutionPolicy"
foreach ($cmdlet in $list) {& $cmdlet | Get-Member -Name MachineName}IdentifyGet members for an array
$array = @(1,'hello')
$array | Get-MemberIdentifyDetermine which object properties you can set
$File = Get-Item C:\test\textFile.txt
$File.psobject.Properties | Where-Object IsSettable | Select-Object -Property NameIdentifyList the properties of an object in the order they were created
$Asset = New-Object -TypeName psobject
$d = [ordered]@{Name="Server30";System="Server Core";PSVersion="4.0"}
$Asset | Add-Member -NotePropertyMembers $d -TypeName Asset
$Asset.psobject.Properties | Select-Object Name, ValueIdentifyIts page in the reference: Get-Member.
Parameters
-ForceAdds the intrinsic members and the compiler-generated get_ and set_ methods to the display. The following list describes the properties that are added when you use the Force parameter:
- psbase: The original properties of the .NET object without extension or adaptation. These are
the properties defined for the object class.
- psadapted: The properties and methods defined in the PowerShell extended type system.
- psextended: The properties and methods that were added in the Types.ps1xml files or using the
Add-Member cmdlet.
- psobject: The adapter that converts the base object to a PowerShell PSObject object.
- pstypenames: A list of object types that describe the object, in order of specificity. When
formatting the object, PowerShell searches for the types in the Format.ps1xml files in the
PowerShell installation directory ($PSHOME). It uses the formatting definition for the first
type that it finds.
By default, Get-Member gets these properties in all views except Base and Adapted, but doesn't display them.-InputObjectSpecifies the object whose members are retrieved.
Using the InputObject parameter isn't 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.-MemberTypeSpecifies 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
These values are defined as a flag-based enumeration. You can combine multiple values together to set multiple flags using this parameter. The values can be passed to the MemberType parameter as an array of values or as a comma-separated string of those values. The cmdlet will combine the values using a binary-OR operation. Passing values as an array is the simplest option and also allows you to use tab-completion on the values.
For information about these values, see PSMemberTypes Enumeration.
Not all objects have every type of member. If you specify a member type that the object doesn't have, 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.-NameSpecifies 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.-StaticIndicates 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 or Force parameters, the cmdlet ignores
those parameters. If you use the Static parameter with the MemberType parameter,
Get-Member gets only the members that belong to both sets.-ViewSpecifies that this cmdlet gets only particular types properties and methods. Specify one or more of the values. The default is Adapted, Extended.
The acceptable values for this parameter are:
- Base. Gets only the original properties and methods of the .NET object (without extension or
adaptation).
- Adapted. Gets only the properties and methods defined in the PowerShell extended type system.
- Extended. Gets only the properties and methods that were added in a 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.