I have the following script.
$cols = Get-MyColumns # returns "a","b","c",...
$cols2 = $cols, @{n='x'; e={"0"}} # Add a new column
import-csv test.csv | select -property $cols2
However the script gets the following error.
select : Cannot convert System.Object[] to one of the following types {System.String, System.Management.Automation.ScriptBlock}. At line:1 char:xx + Import-Csv test.csv | select -Property $cols2 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Select-Object], NotSupportedException + FullyQualifiedErrorId : DictionaryKeyUnknownType,Microsoft.PowerShell.Commands.SelectObjectCommand
The string array cannot be concatenated with the customized column definition. What's the workaround of it?