Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I often find that I have to surround a command in parentheses and then use the property access operator (dot-syntax) to get the value of a property. This is rather annoying since I have to go back to the beginning of the line when I'd rather just keep typing where I am. It is especially annoying when I am in the middle of a larger set of piped commands.

Example

If I have the following command

Get-PSProvider FileSystem

and I want to get the Drives property, I would have to surround the whole command in parentheses first:

(Get-PSProvider FileSystem).Drives

Is there a faster way to get the value of a single property?

share|improve this question
up vote 12 down vote accepted

You can use Select-Object -ExpandProperty <property name>. This can be shortened using the alias select and only typing part of the property name:

Get-PSProvider FileSystem| select -exp Drives

An additional benefit to this method is that you can access a single property for multiple objects.

This will not return anything (Update: This does work in PowerShell v3.):

(Get-PSProvider).Drives

However, this will return the drives for all providers:

Get-PSProvider| select -exp Drives
share|improve this answer
    
Very interesting. Thank you for the correction. – soandos Dec 27 '11 at 3:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .