How come I can successfully pipe result of a cmdlet to Get-Member, but not through a variable?

PM> Get-ProjectFolder "Services" -Project "Foobar" | Get-Member


   TypeName: System.__ComObject#{8e2f1269-185e-43c7-8899-950ad2769ccf}

Name              MemberType Definition                                  
----              ---------- ----------                                  
AddFolder         Method     ProjectItem AddFolder (string, string)      
AddFromDirectory  Method     ProjectItem AddFromDirectory (string)       
AddFromFile       Method     ProjectItem AddFromFile (string)            
AddFromFileCopy   Method     ProjectItem AddFromFileCopy (string)        
AddFromTemplate   Method     ProjectItem AddFromTemplate (string, string)
Item              Method     ProjectItem Item (Variant)                  
ContainingProject Property   Project ContainingProject () {get}          
Count             Property   int Count () {get}                          
DTE               Property   DTE DTE () {get}                            
Kind              Property   string Kind () {get}                        
Parent            Property   IDispatch Parent () {get}                   

.

PM> $f = Get-ProjectFolder "Services" -Project "Foobar"
PM> $f | Get-Member
Get-Member : You must specify an object for the Get-Member cmdlet.
At line:1 char:6
+ $f | Get-Member
+      ~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Get-Member], InvalidOperationException
    + FullyQualifiedErrorId : NoObjectInGetMember,Microsoft.PowerShell.Commands.GetMemberCommand

Edit: https://i.stack.imgur.com/mEMCu.png

enter image description here

有帮助吗?

解决方案

How about Get-Member -InputObject $f instead of piping? There is a difference, as the help says, but it should consider only collections:

-InputObject

Specifies the object whose members are retrieved.

Using the InputObject parameter is not the same as piping an object to Get-Member.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top