Startsidan  ▸  Texter  ▸  Teknikblogg

Anders Hesselbom

Programmerare, skeptiker, sekulärhumanist, antirasist.
Författare till bok om C64 och senbliven lantis.
Röstar pirat.

Getting information

2010-11-07

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("https://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.

Categories: PowerShell

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 *



En kopp kaffe!

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

Bjud på en kopp kaffe!

Om...

Kontaktuppgifter, med mera, finns här.

Följ mig

Twitter Instagram
GitHub RSS

Public Service

Folkbildning om public service.

Hem   |   linktr.ee/hesselbom   |   winsoft.se   |   80tal.se   |   Filmtips