Bart De Vos
Bart De Vos

Reputation: 631

Passing multiple string parameters in PowerShell

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?

Upvotes: 0

Views: 2255

Answers (1)

Shay Levy
Shay Levy

Reputation: 126902

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

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

Upvotes: 1

Related Questions