2
wwwroot> $nsmgr.gettype()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     False    XmlNamespaceManager                      System.Object

wwwroot> Get-Member -InputObject $nsmgr

   TypeName: System.Xml.XmlNamespaceManager

wwwroot> $nsmgr | Get-Member

   TypeName: System.String

It seems like Get-Member is type-converting to a String in first Get-Member call, but this seems to be very strange behavior for a Cmdlet like Get-Member.

I've read How to use PowerShell Get-Member cmdlet but I don't believe that's the same issue.

4

1 回答 1

5

XmlNamespaceManager implements IEnumerable so PowerShell will output the items contained within the XmlNamespaceManager down the pipeline. To prevent that you can use the comma operator:

,$nsmgr | Get-Member

This will create a simple array wrapper around the XmlNamespaceManager so that it gets propagated down the pipe instead of its contents.

于 2012-12-10T20:42:29.833 回答