# Get-Member (Alias: gm)

When working with PowerShell, it is crucial to understand the properties and methods of objects you are dealing with. One of the most useful cmdlets for this purpose is `Get-Member`. This cmdlet provides insights into the structure of objects, allowing users to interact effectively with them.

***

### 1. What is `Get-Member`, and Why is it Important?

#### **Definition**

`Get-Member` is a cmdlet in PowerShell that reveals the properties, methods, and events available on an object. Each object in PowerShell is based on a .NET class, and `Get-Member` allows users to inspect these objects to understand their capabilities.

#### **Why Use `Get-Member`?**

* When working with unfamiliar objects, `Get-Member` helps identify the available properties and methods.
* It enables users to discover how they can manipulate or retrieve data from an object.
* It is useful when troubleshooting scripts, as it provides a clear view of what an object contains.

#### **Example**

```
Get-Process | Get-Member
```

This command retrieves a list of running processes and pipes them into `Get-Member`. The output displays:

* The type/class name (`System.Diagnostics.Process`)
* The list of properties and methods available for process objects.
*

```
<figure><img src="https://2325329360-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxV3NRyPsEjkbBdVUnFZk%2Fuploads%2F5YjQwh5mRJfLMX4PBm2A%2Fimage.png?alt=media&#x26;token=169269ed-88c2-4051-9666-ec7f111cfbde" alt=""><figcaption></figcaption></figure>
```

***

### 2. How `Get-Member` Works

#### **Basic Functionality**

Whenever an object is piped into `Get-Member`, it inspects the first object in the pipeline and returns:

1. The type or class name of the object.
2. The properties and methods available for that object.

#### **Example: Examining a Registry Item**

```
$x = Get-Item HKLM:\
$x | Get-Member
```

* `Get-Item HKLM:\` retrieves an item from the registry.
* Piping `$x` into `Get-Member` displays its available members.

This is useful when dealing with objects of unknown types.

<figure><img src="https://2325329360-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxV3NRyPsEjkbBdVUnFZk%2Fuploads%2FXLz5Pcz59rZT5SbztIv3%2Fimage.png?alt=media&#x26;token=1fe510a2-e1e3-40a3-9ea7-1a05ca783b7c" alt=""><figcaption></figcaption></figure>

***

### 3. Using `Get-Member` with Different Object Types

#### **Inspecting a Collection vs. an Item Inside a Collection**

When working with collections (arrays, lists, etc.), it is important to differentiate between inspecting an individual item and inspecting the collection itself.

**Example 1: Inspecting the First Item in a Collection**

```
$output = Get-ChildItem C:\
$output | Get-Member
```

* This command retrieves items from `C:\` (files and directories).
* Piping `$output` into `Get-Member` shows the members of the first item in the collection.
*

```
<figure><img src="https://2325329360-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxV3NRyPsEjkbBdVUnFZk%2Fuploads%2FQBTMlsTHIXQlj9GQ4SGv%2Fimage.png?alt=media&#x26;token=134fc1a3-ad1c-4b82-88bb-545722d926d6" alt=""><figcaption></figcaption></figure>
```

**Example 2: Inspecting the Collection Itself**

```
Get-Member -InputObject $output
```

* Using `-InputObject $output` inspects the array itself (`System.Object[]`), revealing members like `Count`, `Length`, and `SyncRoot`.
*

```
<figure><img src="https://2325329360-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxV3NRyPsEjkbBdVUnFZk%2Fuploads%2FRjqSBZbP55lCAGyxUPQ2%2Fimage.png?alt=media&#x26;token=3466a358-65ca-4f52-91f1-93506e19268c" alt=""><figcaption></figcaption></figure>
```

#### **Understanding How `Get-Member` Handles Mixed Object Types**

If multiple object types are piped into `Get-Member`, it does not list the members of every single object instance. Instead, it groups objects by type and displays the members for each unique type.

**Example: Mixed Object Types**

```
Get-ChildItem | Get-Member
```

* If `Get-ChildItem` returns a mix of files and directories, `Get-Member` will display members separately for `System.IO.FileInfo` and `System.IO.DirectoryInfo`.
*

```
<figure><img src="https://2325329360-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxV3NRyPsEjkbBdVUnFZk%2Fuploads%2FYtG2tJu9tMZMOHSKFm7J%2Fimage.png?alt=media&#x26;token=12a2f52c-c9c1-4d56-92bd-320deab2cd80" alt=""><figcaption></figcaption></figure>
```

***

### 4. Alternative Ways to Use `Get-Member`

#### **Using the `-MemberType` Parameter**

To filter results, use the `-MemberType` parameter.

```
Get-Process | Get-Member -MemberType Property
```

*

```
<figure><img src="https://2325329360-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxV3NRyPsEjkbBdVUnFZk%2Fuploads%2FngAO3eMg8lO3ZH90zBtt%2Fimage.png?alt=media&#x26;token=0a9dcfcf-2199-4a5d-a0a5-b7e5a3457823" alt=""><figcaption></figcaption></figure>
```

* This command displays only the properties of `System.Diagnostics.Process`.

```
Get-Process | Get-Member -MemberType Method
```

* This command displays only the methods of `System.Diagnostics.Process`.

#### **Using the `-Name` Parameter to Search for a Specific Member**

```
Get-Process | Get-Member -Name HandleCount
```

* This checks if `HandleCount` exists as a property or method.

#### **Inspecting Static Members**

```
[System.Math] | Get-Member -Static
```

* This displays static methods and properties of `System.Math`.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mohab-yehia.gitbook.io/sec505/welcome-to-securing-windows-with-powershell-a-deep-dive-into-sec505/sec-505.1/get-member-alias-gm.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
