2
get-service| get-member #gives output.

While

$a= get-service 
get-member $a # generates error 
"get-member : No object has been specified to the get-member cmdlet.
At line:1 char:1
+ get-member $a
+ ~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Get-Member], InvalidOperationException
    + FullyQualifiedErrorId : NoObjectInGetMember,Microsoft.PowerShell.Commands.GetMemberCommand"

Why so??

1 Answer 1

3

get-service| get-member sends each service object, one at a time, to the Get-Member cmdlet, Each object is bound to the InputObject parameter (ByValue) and is processed accordingly.

When you do get-member $a you are passing $a to the first position parameter which is the Name parameter, not to the InputObject parameter. In order to get the members of $a (the collection itself):

Get-Member -InputObject $a
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks shay. As you mention $a would return the collection of object. How can I get type of individual object and not the collection when using with Get-Member??
Pipe it to the Get-Member cmdlet
By the way, $a[0].GetType().FullName would get you the type name of the first object in the collection
Thanks very much for the prompt reply.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.