PowerShell for Windows Admins

Mar 20 2014   12:36PM GMT

Where’s the value

Richard Siddaway Richard Siddaway Profile: Richard Siddaway


PowerShell is object based – its the one fact that is mentioned in very introduction to PowerShell – and its the use of objects that gives PowerShell its reach and power.

The use of objects has one tiny drawback. When you want the actual value of a property you have to do slightly more work.

This is representative of a typical PowerShell expression

£> Get-Process powershell | select Path




Now if you want the value of path itself to use elsewhere you have to do one of three things:

£> $proc = Get-Process powershell

£> $proc.Path



£> $path = Get-Process powershell | select -ExpandProperty Path

£> $path



£> $proc = (Get-Process powershell | select Path).path

£> $path


The first one gives you an object to work with. If you want other properties you can access them later.

The other two options give you a variable containing just the information you need – the value of the Path property.

Which one works best – depends on what you are doing. I use all three techniques on a regular basis though tend to prefer using option 2 to option 3 – mainly because I find it easier to read when I come back to the script weeks, months or even years later.

 Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: