Passing multiple string parameters in PowerShell

Tag: powershell , csv Author: lovsy Date: 2013-09-24

When exporting data to csv with Export-Csv not all data is exported because not all fields show up in Get-Member(object properties are not equal between objects). I can, however, get them out by using Select-Object.

I can build this list dynamically, but I'm unable to pass it correctly.

Example:

$test = "`"Contract`", `"Hostname`", `"Description`"" //Code generated
$selected | Select-Object $($test)

How should I do this?

Best Answer

You can pass an array of strings representing property names. For example:

$test = "Name","FullName","Length"
Get-ChildItem | Select-Object $test