Skip to content

Commit

Permalink
Fix Example for Get-Member -InputObject (#3373)
Browse files Browse the repository at this point in the history
* Fix Example for Get-Member -InputObject

* Fix syntax error
* Fix command sequence and commands used
* Fix unclear example sequence

Thanks to [Ramon TAN](https://powershell.org/forums/topic/get-member-examples-different-results-on-my-pc/#post-127867) for stumbling across this in confusion!

* Update Get-Member.md

Update v5 document with change

* Update Get-Member.md

update v5.0 document with change

* Update Get-Member.md

Update v4.0 document

* Update Get-Member.md

Update v3.0 document

* Update Get-Member.md

Trim prompt from examples in 3.0 file

* Update Get-Member.md

Trim path from prompts in 4.0 file

* Update Get-Member.md

Trim paths from prompts in 5.0 document

* Update Get-Member.md

Trim Paths from prompts in 5.1 file

* Update Get-Member.md

2nd pass for 5.0 file

* Update Get-Member.md

Trim paths from prompts in v6 file
  • Loading branch information
vexx32 authored and sdwheeler committed Dec 3, 2018
1 parent f55ccc8 commit 756a34d
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 82 deletions.
24 changes: 16 additions & 8 deletions reference/3.0/Microsoft.PowerShell.Utility/Get-Member.md
Expand Up @@ -115,7 +115,7 @@ In this case, the extended member is the Name property, which is an alias proper
### Example 4

```powershell
PS C:\> Get-EventLog -Log System | Get-Member -MemberType ScriptProperty
PS> Get-EventLog -Log System | Get-Member -MemberType ScriptProperty
TypeName: System.Diagnostics.EventLogEntry
Expand Down Expand Up @@ -158,20 +158,28 @@ The results show that only process objects (System.Diagnostics.Process) and serv
### Example 6

```
PS> $a = get-member -inputobject @(1)
PS> $a.count
PS> $A = @(1)
PS> $A.Count
1
PS> $a = get-member -inputobject 1,2,3
PS> Get-Member -InputObject $A
TypeName: System.Object[]
Name MemberType Definition
---- ---------- ----------
Count AliasProperty Count = Length
Address Method System.Object& Address(Int32 )
Clone Method System.Object Clone()
...
PS> $a.count
1
PS> $A = @(1,2,3)
PS> Get-Member -InputObject $A
TypeName: System.Object[]
Name MemberType Definition
---- ---------- ----------
Count AliasProperty Count = Length
Address Method System.Object& Address(Int32 )
Clone Method System.Object Clone()
...
PS> $A.Count
3
```

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.
Expand Down Expand Up @@ -454,4 +462,4 @@ For more information about the $this variable, see about_Automatic_Variables.

[about_Methods](../Microsoft.PowerShell.Core/About/about_Methods.md)

[about_Objects](../Microsoft.PowerShell.Core/About/about_Objects.md)
[about_Objects](../Microsoft.PowerShell.Core/About/about_Objects.md)
48 changes: 28 additions & 20 deletions reference/4.0/Microsoft.PowerShell.Utility/Get-Member.md
Expand Up @@ -32,7 +32,7 @@ To get only certain types of members, such as NoteProperties, use the MemberType

### Example 1
```
PS C:\> get-service | get-member
PS> get-service | get-member
TypeName: System.ServiceProcess.ServiceController
Name MemberType Definition
Expand Down Expand Up @@ -78,8 +78,8 @@ As such, it gets all member types, but it does not get static members and does n

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

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.
Expand All @@ -95,7 +95,7 @@ The second command shows how to display the value of the PSBase property of the

### Example 3
```
PS C:\> get-service| get-member -view extended
PS> get-service| get-member -view extended
TypeName: System.ServiceProcess.ServiceController
Name MemberType Definition
Expand All @@ -110,7 +110,7 @@ In this case, the extended member is the Name property, which is an alias proper

### Example 4
```powershell
PS C:\> Get-EventLog -Log System | Get-Member -MemberType ScriptProperty
PS> Get-EventLog -Log System | Get-Member -MemberType ScriptProperty
TypeName: System.Diagnostics.EventLogEntry
Expand All @@ -126,8 +126,8 @@ The command returns the EventID property of the **EventLog** object.

### Example 5
```
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}
PS> $a = "get-process", "get-service", "get-culture", "get-psdrive", "get-executionpolicy"
PS> foreach ($cmdlet in $a) {invoke-command $cmdlet | get-member -name machinename}
TypeName: System.Diagnostics.Process
Name MemberType Definition
Expand All @@ -151,20 +151,28 @@ The results show that only process objects (System.Diagnostics.Process) and serv

### Example 6
```
PS C:\> $a = get-member -inputobject @(1)
PS C:\> $a.count
PS> $A = @(1)
PS> $A.Count
1
PS C:\> $a = get-member -inputobject 1,2,3
PS> Get-Member -InputObject $A
TypeName: System.Object[]
Name MemberType Definition
---- ---------- ----------
Count AliasProperty Count = Length
Address Method System.Object& Address(Int32 )
Clone Method System.Object Clone()
...
PS C:\> $a.count
1
PS> $A = @(1,2,3)
PS> Get-Member -InputObject $A
TypeName: System.Object[]
Name MemberType Definition
---- ---------- ----------
Count AliasProperty Count = Length
Address Method System.Object& Address(Int32 )
Clone Method System.Object Clone()
...
PS C:\> $A.Count
3
```

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.
Expand All @@ -179,8 +187,8 @@ The fourth command uses the Count property of the array to find the number of ob

### Example 7
```
PS C:\> $file = get-item c:\test\textFile.txt
PS C:\> $file.psobject.properties | where-object {$_.issettable} | format-table -property name
PS> $file = get-item c:\test\textFile.txt
PS> $file.psobject.properties | where-object {$_.issettable} | format-table -property name
Name
----
Expand All @@ -199,7 +207,7 @@ LastWriteTime
LastWriteTimeUtc
Attributes
PS C:\> [appdomain]::CurrentDomain.GetAssemblies() | foreach-object { $_.getexportedtypes() } | foreach-object {$_.getproperties() | where-object {$_.canwrite }} | select-object reflectedtype, name
PS> [appdomain]::CurrentDomain.GetAssemblies() | foreach-object { $_.getexportedtypes() } | foreach-object {$_.getproperties() | where-object {$_.canwrite }} | select-object reflectedtype, name
```

This example shows how to determine which properties of an object can be changed.
Expand All @@ -213,8 +221,8 @@ The third command gets the changeable properties of all objects in your Windows

### Example 8
```
PS C:\> $s = get-service
PS C:\> $s | get-member
PS> $s = get-service
PS> $s | get-member
TypeName: System.ServiceProcess.ServiceController
Name MemberType Definition
Expand All @@ -227,7 +235,7 @@ Continue Method System.Void Continue()
CreateObjRef Method System.Runtime.Remoting.ObjRef CreateObjRef(type requestedTy
Dispose Method System.Void Dispose()
...
PS C:\> get-member -inputObject $s
PS> get-member -inputObject $s
TypeName: System.Object[]
Name MemberType Definition
Expand Down Expand Up @@ -437,4 +445,4 @@ For more information about the $this variable, see about_Automatic_Variables.

[about_Methods](../Microsoft.PowerShell.Core/About/about_Methods.md)

[about_Objects](../Microsoft.PowerShell.Core/About/about_Objects.md)
[about_Objects](../Microsoft.PowerShell.Core/About/about_Objects.md)
47 changes: 29 additions & 18 deletions reference/5.0/Microsoft.PowerShell.Utility/Get-Member.md
Expand Up @@ -32,7 +32,7 @@ To get only certain types of members, such as **NoteProperties**, use the *Membe

### Example 1: Get the members of process objects
```
PS C:\> Get-Service | Get-Member
PS> Get-Service | Get-Member
TypeName: System.ServiceProcess.ServiceController
Name MemberType Definition
---- ---------- ----------
Expand Down Expand Up @@ -77,8 +77,8 @@ As such, it gets all member types, but it does not get static members and does n

### Example 2: Get members of service objects
```
PS C:\> Get-Service | Get-Member -Force
PS C:\> (Get-Service Schedule).PSBase
PS> Get-Service | Get-Member -Force
PS> (Get-Service Schedule).PSBase
```

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.
Expand All @@ -94,7 +94,7 @@ The second command shows how to display the value of the PSBase property of the

### Example 3: Get extended members of service objects
```
PS C:\> Get-Service| Get-Member -View Extended
PS> Get-Service| Get-Member -View Extended
TypeName: System.ServiceProcess.ServiceController
Name MemberType Definition
---- ---------- ----------
Expand All @@ -108,7 +108,7 @@ In this case, the extended member is the Name property, which is an alias proper

### Example 4: Get script properties of event log objects
```
PS C:\> Get-EventLog -Log System | Get-Member -MemberType ScriptProperty
PS> Get-EventLog -Log System | Get-Member -MemberType ScriptProperty
TypeName: System.Diagnostics.EventLogEntry
Name MemberType Definition
---- ---------- ----------
Expand All @@ -123,8 +123,8 @@ The command returns the EventID property of the **EventLog** object.

### Example 5: Get objects with a specified 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}
PS> $A = "Get-Process", "Get-Service", "Get-Culture", "Get-PSDrive", "Get-ExecutionPolicy"
PS> ForEach ($Cmdlet in $A) {Invoke-Command $Cmdlet | Get-Member -Name MachineName}
TypeName: System.Diagnostics.Process
Name MemberType Definition
---- ---------- ----------
Expand All @@ -145,19 +145,28 @@ The results show that only process objects (**System.Diagnostics.Process**) and

### Example 6: Get members for an array
```
PS C:\> $A = Get-Member - InputObject @(1)
PS C:\> $A.Count
PS> $A = @(1)
PS> $A.Count
1
PS C:\> $A = Get-Member -InputObject 1,2,3
PS> Get-Member -InputObject $A
TypeName: System.Object[]
Name MemberType Definition
---- ---------- ----------
Count AliasProperty Count = Length
Address Method System.Object& Address(Int32 )
Clone Method System.Object Clone()
...
PS C:\> $A.Count
1
PS> $A = @(1,2,3)
PS> Get-Member -InputObject $A
TypeName: System.Object[]
Name MemberType Definition
---- ---------- ----------
Count AliasProperty Count = Length
Address Method System.Object& Address(Int32 )
Clone Method System.Object Clone()
...
PS> $A.Count
3
```

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.
Expand All @@ -172,8 +181,8 @@ The fourth command uses the Count property of the array to find the number of ob

### Example 7: Determine which object properties you can set
```
PS C:\> $File = Get-Item c:\test\textFile.txt
PS C:\> $File.psobject.properties | Where-Object {$_.issettable} | Format-Table -Property name
PS> $File = Get-Item c:\test\textFile.txt
PS> $File.psobject.properties | Where-Object {$_.issettable} | Format-Table -Property name
Name
----
PSPath
Expand All @@ -189,7 +198,8 @@ LastAccessTime
LastAccessTimeUtc
LastWriteTime
LastWriteTimeUtc
Attributes PS C:\> [appdomain]::CurrentDomain.GetAssemblies() | ForEach-Object { $_.getexportedtypes() } | ForEach-Object {$_.getproperties() | Where-Object {$_.canwrite }} | Select-Object reflectedtype, name
Attributes
PS> [appdomain]::CurrentDomain.GetAssemblies() | ForEach-Object { $_.getexportedtypes() } | ForEach-Object {$_.getproperties() | Where-Object {$_.canwrite }} | Select-Object reflectedtype, name
```

This example shows how to determine which properties of an object can be changed.
Expand All @@ -203,8 +213,8 @@ The third command gets the changeable properties of all objects in your Windows

### Example 8: Get members of each item in a collection
```
PS C:\> $S = Get-Service
PS C:\> $S | Get-Member
PS> $S = Get-Service
PS> $S | Get-Member
TypeName: System.ServiceProcess.ServiceController
Name MemberType Definition
---- ---------- ----------
Expand All @@ -215,7 +225,8 @@ Close Method System.Void Close()
Continue Method System.Void Continue()
CreateObjRef Method System.Runtime.Remoting.ObjRef CreateObjRef(type requestedTy
Dispose Method System.Void Dispose()
... PS C:\> Get-Member -InputObject $S
...
PS> Get-Member -InputObject $S
TypeName: System.Object[]
Name MemberType Definition
---- ---------- ----------
Expand Down

0 comments on commit 756a34d

Please sign in to comment.