Getting information

The cmdlet for finding out what capabilities (members) an object have, is called Get-Member. You can pass any object to this cmdlet, and you can filter its return. This will give all members of a regular string object:

Get-Member -InputObject "Hello"

This will only display the properties, not for example the functions:

Get-Member -InputObject "Hello" -MemberType Properties

And this will display all the capabilities of a Uri object:

$x=New-Object System.Uri("http://www.winsoft.se/")
Get-Member -InputObject $x

The Environment class in the System namespace holds all known information about the local machine and its operating system. This will display the name of the local computer:

[System.Environment]::MachineName

And this will display the version of your operating system:

[System.Environment]::OSVersion

MachineName and OSVersion are examples of class members, and they can be displayed aswell. To just show the class members of a string object, type:

Get-Member -InputObject "Hello" -Static

However, if you can’t get a reference to the objekt, you can’t use the Get-Member cmdlet. So the Get-Member cannot tell what the Environment class holds, because you can’t create an instance from that class. Reading the MSDN documentation seems to be the best way to get information. If someone knows a nice trick here, please post a comment.

Bjud mig på en kopp kaffe (20:-) som tack för bra innehåll:

Bjud mig på en kopp kaffe (20:-) som tack för bra innehåll!

Comments

Important information: If you have not commented before, your comment will be reviewed before it is published. This means that you will not see it immediately, but I have received it. This is not because I want to filter comments, but because I want to prevent spam and advertising.

One response to “Getting information”

  1. […] This post was mentioned on Twitter by Anders Hesselbom, Sean Kearney. Sean Kearney said: RT @ahesselbom: PowerShell: Getting information. http://bit.ly/du654B […]

Leave a Reply

Your email address will not be published. Required fields are marked *