-ExcludeProperty with List of Properties in a Variable

Hi,
I need to exclude columns from a CSV file and then write it out to a new CSV file. This of course works:
$NewCSV = Import-Csv $AFileFullPath | select-object * -ExcludeProperty user_id,first_name,last_name,email -Verbose
$NewCSV | Export-Csv -NoTypeInformation -LiteralPath $FileFullPath -Verbose
What I need to do is pass that list of columns as a parameter. I’m using a non-PowerShell application to pass parameters to the script. The problem is, it’s treating the parameter as single string. I’ve tried passing them as follows:
@(‘user_id’,‘first_name’,‘last_name’,‘email’)
“‘user_id’,‘first_name’,‘last_name’,‘email’”

‘user_id’,‘first_name’,‘last_name’,‘email’</p>
I know this works too:
$ExcludeColumns = @(‘user_id’,‘first_name’,‘last_name’,‘email’)
I somehow need to pass in the columns like this:
user_id,first_name,last_name,email
To have something similar to this:
$NewCSV = Import-Csv $FileFullPath | select-object * -ExcludeProperty $ExcludeColumns -Verbose
$NewCSV | Export-Csv -NoTypeInformation -LiteralPath $FileFullPath -Verbose
So that if any other columns need to be updated, I can just add it to the application without having to adjust the code. I was thinking splitting the variable at the commas and assigning to an array, but somehow loop through the array to exclude the columns but not sure if or how that could be done. Ideas?

Hi,

I need to exclude columns from a CSV file and then write it out to a new CSV file. This of course works:

$NewCSV = Import-Csv $AFileFullPath | select-object * -ExcludeProperty user_id,first_name,last_name,email -Verbose

$NewCSV | Export-Csv -NoTypeInformation -LiteralPath $FileFullPath -Verbose

What I need to do is pass that list of columns as a parameter. I’m using a non-PowerShell application to pass parameters to the script. The problem is, it’s treating the parameter as single string. I’ve tried passing them as follows:

@(‘user_id’,‘first_name’,‘last_name’,‘email’)

“‘user_id’,‘first_name’,‘last_name’,‘email’”

‘user_id’,‘first_name’,‘last_name’,‘email’

I know this works too:

$ExcludeColumns = @(‘user_id’,‘first_name’,‘last_name’,‘email’)

I somehow need to pass in the columns like this:

user_id,first_name,last_name,email

To have something similar to this:

$NewCSV = Import-Csv $FileFullPath | select-object * -ExcludeProperty $ExcludeColumns -Verbose

$NewCSV | Export-Csv -NoTypeInformation -LiteralPath $FileFullPath -Verbose

So that if any other columns need to be updated, I can just add it to the application without having to adjust the code. I was thinking splitting the variable at the commas and assigning to an array, but somehow loop through the array to exclude the columns but not sure if or how that could be done. Ideas?