I'm trying to figure out a way to pass a list of columns as a parameter to be excluded when importing a CSV file. I can get the code working when I explicitly list the columns, but want to be able pass in a parameter of the list of columns from the calling application so that I don't have to update the script each time more columns need to be excluded.
This of course works:
$NewCsv = Import-CSV $FileFullPath | Select * -ExcludeProperty user_id,first_name,last_name,email
But this doesn't work:
$removecolumns = "'user_id','first_name','last_name','email'"
$NewCsv = Import-CSV $AuraFileFullPath | Select * -ExcludeProperty $removecolumns
Nor this:
$removecolumns = "user_id,first_name,last_name,email"
$NewCsv = Import-CSV $AuraFileFullPath | Select * -ExcludeProperty $removecolumns
Or this:
$removecolumns = @('user_id','first_name','last_name','email')
$NewCsv = Import-CSV $AuraFileFullPath | Select * -ExcludeProperty $removecolumns
I'll keep digging but any suggestions would be most appreciated!