0

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!

1 Answer 1

1

I ended up getting it working using

 $removecolumns = @('user_id','first_name','last_name','email')
$NewCsv = Import-CSV $AuraFileFullPath | Select * -ExcludeProperty $removecolumns

The application that calls the script and passes in @('user_id','first_name','last_name','email') as a parameter was the problem.

Thanks!

Sign up to request clarification or add additional context in comments.

1 Comment

As a semantic sugar, you might remove the @ sign and parentheses: $removecolumns = 'user_id','first_name','last_name','email'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.