如何获取get-member cmdlet的全文(特别是定义)

时间:2014-11-06 09:01:10

标签: powershell

E.g。用:

new-object -comobject WScript.Network |get-member -verbose -View all

我有:

   TypeName: System.__ComObject#{24be5a31-edfe-11d2-b933-00104b365c9f}

Name                        MemberType Definition
----                        ---------- ----------
AddPrinterConnection        Method     void AddPrinterConnection (string, st...
AddWindowsPrinterConnection Method     void AddWindowsPrinterConnection (str...
CreateObjRef                Method     System.Runtime.Remoting.ObjRef Create...
EnumNetworkDrives           Method     IWshCollection EnumNetworkDrives ()
EnumPrinterConnections      Method     IWshCollection EnumPrinterConnections ()
Equals                      Method     bool Equals(System.Object obj)
GetHashCode                 Method     int GetHashCode()
GetLifetimeService          Method     System.Object GetLifetimeService()
GetType                     Method     type GetType()
InitializeLifetimeService   Method     System.Object InitializeLifetimeServi...
MapNetworkDrive             Method     void MapNetworkDrive (string, string,...
RemoveNetworkDrive          Method     void RemoveNetworkDrive (string, Vari...
RemovePrinterConnection     Method     void RemovePrinterConnection (string,...
SetDefaultPrinter           Method     void SetDefaultPrinter (string)
ToString                    Method     string ToString()
ComputerName                Property   string ComputerName () {get}
Organization                Property   string Organization () {get}
Site                        Property   string Site () {get}
UserDomain                  Property   string UserDomain () {get}
UserName                    Property   string UserName () {get}
UserProfile                 Property   string UserProfile () {get}

DEFINTION文本并不完整。当我增加控制台大小时,我可以完全定义定义。但我认为这是一种解决方法(当我输出到文件时也需要这样做)。如何在不改变控制台大小的情况下获得全文?是否可能?

1 个答案:

答案 0 :(得分:1)

如果将结果放入变量中,则可以像数组一样索引它们:

$x = new-object -comobject WScript.Network |get-member -verbose -View all
$x[0]

给出了

   TypeName: System.__ComObject#{24be5a31-edfe-11d2-b933-00104b365c9f}

Name                 MemberType Definition
----                 ---------- ----------
AddPrinterConnection Method     void AddPrinterConnection (string, string, Variant, Variant, Variant)
然后,您可以像这样获取对象上的单个属性:

PS> $x[0].definition
void AddPrinterConnection (string, string, Variant, Variant, Variant)

获取更多方法信息的另一种方法是在对象上输入方法名称并留下空格:

PS> (new-object -comobject WScript.Network).addprinterconnection

MemberType          : Method
OverloadDefinitions : {void AddPrinterConnection (string, string, Variant, Variant, Variant)}
TypeNameOfValue     : System.Management.Automation.PSMethod
Value               : void AddPrinterConnection (string, string, Variant, Variant, Variant)
Name                : AddPrinterConnection
IsInstance          : True

只是习惯了你正在处理.net对象的想法,并且可以用它们做很多正常的面向对象的东西:)