powershell members of an object, pipe, inputobject

use Get-Member

pipe the object to get-member  or use -InputObject

Get-Member -Force will get all members, check help for diff options

PS C:\>Get-Service | Get-Member
PS C:\>”hello” | Get-Member
PS C:\>1 | Get-Member
PS C:\>Get-Member -InputObject “hello”

Piping and -InputObject are different in that – when the input is via pipe, get-member gives information about all the different types of objects piped to it, where as for -InputObject it gives the type of the container itself

for example:

PS C:\>1 | Get-Member
PS C:\> Get-Member -InputObject 1

Will return information for TypeName: System.Int32

whereas

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

will return information about the windows service controller object and the array object respectively since the second one treats $a as it is ‘an array of objects’

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s