A newbie question:
The command:
[Math] | Get-Member
Returns all members of System.RuntimeType
. Why is that?
Also the command:
Get-Member -InputObject [Math]
Returns all members of System.String
. If [Math]
is interpreted as string here, how can I make it a math object?
Also, does Get-member
takes any positional parameters? How can I tell?
The Get-Member cmdlet gets the members, the properties and methods, of objects. To specify the object, use the InputObject parameter or pipe an object to Get-Member . To get information about static members, the members of the class, not of the instance, use the Static parameter.
Get-Command gets the commands from PowerShell modules and commands that were imported from other sessions. To get only commands that have been imported into the current session, use the ListImported parameter. Without parameters, Get-Command gets all of the cmdlets, functions, and aliases installed on the computer.
To get the properties of an object, use the Get-Member cmdlet. For example, to get the properties of a FileInfo object, use the Get-ChildItem cmdlet to get the FileInfo object that represents a file. Then, use a pipeline operator ( | ) to send the FileInfo object to Get-Member .
To get the object properties, the Get-member cmdlet is used in PowerShell. Specify a cmdlet, use the pipeline operator, and then type the Get-Member cmdlet to see all of the properties available from the specified command.
You are getting a System.RuntimeType from [Math] because that is what it is. It's a Class type as opposed to an object of that particular type. You haven't actually constructed a [Math] object. You will get the same output if you typed:
[String] | gm
However, if you constructed a string object from the String type, you would get the string members:
PS C:\> [String]("hi") | gm
TypeName: System.String
Name MemberType Definition
---- ---------- ----------
Clone Method System.Object Clone()
CompareTo Method System.Int32 CompareTo(Object value), System.Int32 CompareTo(String strB)
Contains Method System.Boolean Contains(String value)
CopyTo Method System.Void CopyTo(Int32 sourceIndex, Char[] destination, Int32 destinationIn...
etc...
Since System.Math has only static members, you can't construct an object of it. To see it's members you can use the GetMembers() function of System.RuntimeType:
[Math].GetMethods()
You can use one of the format-* cmdlets to format the output:
[Math].GetMethods() | format-table
Edit: Oh, and I should add, to invoke one of the static members, you would do it like this:
[Math]::Cos(1.5)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With