How to use PowerShell Get-Member cmdlet

后端 未结 4 453
[愿得一人]
[愿得一人] 2020-12-15 22:52

A newbie question:

The command:

[Math] | Get-Member

Returns all members of System.RuntimeType. Why is that?

Al

4条回答
  •  有刺的猬
    2020-12-15 23:08

    1. Using the get-help get-member command, you get this output

    NAME Get-Member

    SYNOPSIS Gets the properties and methods of objects.

    SYNTAX Get-Member [[-Name] ] [-Force] [-InputObject ] [-MemberType {AliasProperty | CodeProperty | Pro perty | NoteProperty | ScriptProperty | Properties | PropertySet | Method | CodeMethod | ScriptMethod | Methods | P arameterizedProperty | MemberSet | Event | All}] [-Static] [-View {Extended | Adapted | Base | All}] []

    DESCRIPTION The Get-Member cmdlet gets the "members" (properties and methods) of objects.

    To specify the object, use the InputObject parameter or pipe an object to Get-Member. To retrieve information about
     static members (members of the class, not of the instance), use the Static parameter. To get only certain types of
     members, such as NoteProperties, use the MemberType parameter.
    

    RELATED LINKS Online version: http://go.microsoft.com/fwlink/?LinkID=113322 Add-Member Get-Help Get-Command Get-PSDrive

    REMARKS To see the examples, type: "get-help Get-Member -examples". For more information, type: "get-help Get-Member -detailed". For technical information, type: "get-help Get-Member -full".

    1. From the above statement, it shows that get-member only takes in objects and not classes. You use the -Static to view the static members of an object.

    2. When you use [String] without the -Static parameter, you are telling powershell that you are putting an object of type [String], however, you havent created a String object yet from any of your statement so it assumes that [String] is a System.Runtime object representing class String.This is similar if you use [Int] or [Boolean] and other class types.

    3. However, if you use -Static parameter, the powershell interpreter now understands that you want the Static members of String Objects.

提交回复
热议问题