Author Posts

February 3, 2017 at 6:53 pm

hi is it possible to pass a list of properties to a Select-Object cmdlet as a variable?

February 3, 2017 at 7:26 pm

Hi Vadim,

Do you mean so that you don't have to type them out every time? I'm just starting out on this forum so my answer might not be perfect, but storing the property names in an array then using them in select-object sounds like what you mean? (Let's see how I get on with formatting the code!)

$Properties = @("Handles","ProcessName","Id")
Get-Process | Select-Object $Properties

February 3, 2017 at 7:30 pm

Yes, that is possible. You just need to create an array. The array can contain strings representing the names of the properties, expressions (hashtables) to create calculated properties, or both depending on your use case.

$propertyList = 'Id', 'Name', 'Threads'
Get-Process | Select-Object -Property $propertyList

February 4, 2017 at 10:10 am

thanks, just what i needed