3

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.imgur.com/AeUW6Ge.png

enter image description here

4

1 回答 1

5

Get-Member -InputObject $f代替管道怎么样?正如帮助所说,有区别,但它应该只考虑集合:

-输入对象

指定检索其成员的对象。

使用 InputObject 参数与通过管道将对象传递给 Get-Member 不同。

于 2014-05-07T20:07:38.087 回答