Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I often find that I have to surround a command in parentheses and then use the property access to 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

1 Answer 1

up vote 9 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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.