Finding the static methods of a class

Finding the static methods of a class

  • Comments 6

<Edited 7/2/2006 to add categories and tags>

In the previous entry, it showed how you could use the static method GetHostAddresses of the [System.Net.Dns] class to resolve a hostname.  This begs the question, how do you find the static methods of a class.  There are 2 answers to this:

1) SDK documentation.  (remember the trick here - type the name of the class you want and the term "Members" into your search engine).

2) Use Get-Member

Get-Member has a switch -STATIC when directs it to return the static methods and properties of a type.  Here are a couple of examples:


PS> [System.Net.Dns] |Get-Member -Static
   TypeName: System.Net.Dns

Name                  MemberType Definition
----                  ---------- ----------
BeginGetHostAddresses Method     static System.IAsyncResult BeginGetHost...
BeginGetHostByName    Method     static System.IAsyncResult BeginGetHost...
BeginGetHostEntry     Method     static System.IAsyncResult BeginGetHost...
BeginResolve          Method     static System.IAsyncResult BeginResolve...
EndGetHostAddresses   Method     static System.Net.IPAddress[] EndGetHos...
EndGetHostByName      Method     static System.Net.IPHostEntry EndGetHos...
EndGetHostEntry       Method     static System.Net.IPHostEntry EndGetHos...
EndResolve            Method     static System.Net.IPHostEntry EndResolv...
Equals                Method     static System.Boolean Equals(Object obj...
GetHostAddresses      Method     static System.Net.IPAddress[] GetHostAd...
GetHostByAddress      Method     static System.Net.IPHostEntry GetHostBy...
GetHostByName         Method     static System.Net.IPHostEntry GetHostBy...
GetHostEntry          Method     static System.Net.IPHostEntry GetHostEn...
GetHostName           Method     static System.String GetHostName()
ReferenceEquals       Method     static System.Boolean ReferenceEquals(O...
Resolve               Method     static System.Net.IPHostEntry Resolve(S...


PS> [DateTime] |Get-Member -Static
   TypeName: System.DateTime

Name                  MemberType Definition
----                  ---------- ----------
Compare               Method     static System.Int32 Compare(DateTime t1...
DaysInMonth           Method     static System.Int32 DaysInMonth(Int32 y...
Equals                Method     static System.Boolean Equals(DateTime t...
FromBinary            Method     static System.DateTime FromBinary(Int64...
FromFileTime          Method     static System.DateTime FromFileTime(Int...
FromFileTimeUtc       Method     static System.DateTime FromFileTimeUtc(...
FromOADate            Method     static System.DateTime FromOADate(Doubl...
get_Now               Method     static System.DateTime get_Now()
get_Today             Method     static System.DateTime get_Today()
get_UtcNow            Method     static System.DateTime get_UtcNow()
IsLeapYear            Method     static System.Boolean IsLeapYear(Int32 ...
op_Addition           Method     static System.DateTime op_Addition(Date...
op_Equality           Method     static System.Boolean op_Equality(DateT...
op_GreaterThan        Method     static System.Boolean op_GreaterThan(Da...
op_GreaterThanOrEqual Method     static System.Boolean op_GreaterThanOrE...
op_Inequality         Method     static System.Boolean op_Inequality(Dat...
op_LessThan           Method     static System.Boolean op_LessThan(DateT...
op_LessThanOrEqual    Method     static System.Boolean op_LessThanOrEqua...
op_Subtraction        Method     static System.DateTime op_Subtraction(D...
Parse                 Method     static System.DateTime Parse(String s),...
ParseExact            Method     static System.DateTime ParseExact(Strin...
ReferenceEquals       Method     static System.Boolean ReferenceEquals(O...
SpecifyKind           Method     static System.DateTime SpecifyKind(Date...
TryParse              Method     static System.Boolean TryParse(String s...
TryParseExact         Method     static System.Boolean TryParseExact(Str...
MaxValue              Property   static System.DateTime MaxValue {get;set;}
MinValue              Property   static System.DateTime MinValue {get;set;}
Now                   Property   System.DateTime Now {get;}
Today                 Property   System.DateTime Today {get;}
UtcNow                Property   System.DateTime UtcNow {get;}

Jeffrey Snover
Windows PowerShell Architect

PSMDTAG:FAQ: How do I find the static methods of a class?
PSMDTAG:DOTNET static methods, System.Net.DNS

Leave a Comment
  • Please add 6 and 8 and type the answer here:
  • Post
  • Jeffrey Snover posted a great post on the PowerShell Blog
    In the previous entry, it showed how you could...
  • Supplying input object through "-InputObject" results in returning static members of "String" type though.(Get-Member -InputObject [System.Net.Dns] -Static)

    If i don't pass the type name to get-member as a pipeline input, how does "Get-Member" handle "[System.Net.Dns]"?

    Thank you in advance.
  • Put the type in parans and it will work for you:

    Get-Member -InputObject ([System.Net.Dns]) -Static

    The parans say EXECUTE THIS which then produces the TYPE object which is then passed to the parameter.

    Jeffrey Snover
    Windows PowerShell Architect
  • Hello, I hope you see this comment, but I am curious to know how to enumerate WMI static methods. The root\cimv2:Win32_Product class contains several static methods, and I tried using this command to locate them through Powershell: Get-WmiObject Win32_Product | Get-Member -Static It appears to only work on .NET static members ... can this be fixed in the final release, or am I missing something? Thanks
  • Interesting post, haven't used it yet but after reading this will give it a try. Thanks.

Page 1 of 1 (6 items)