jshizzle
jshizzle

Reputation: 487

PowerShell: Import-csv and output values to log file (formatting)

I'm using the following to import users from a csv file and output them to the console:

$(Import-csv $SelectedFile | Select -ExpandProperty EmailAddress)

This displays each EmailAddress on a separate line in the console but I want to output this to a log file too.

Using the following will do this but not a separate line for each EmailAddress like the above. Instead it just shows them on one line with no separator:

"$(Import-csv $SelectedFile | Select -ExpandProperty EmailAddress)" | Tee-Object $UserMigrationLog -Append

Is it possible to do what I ask within this one command?

Upvotes: 2

Views: 422

Answers (1)

Martin Brandl
Martin Brandl

Reputation: 58931

You interpolate the result of Import-CSV into a single string. Just remove the subexpression "$()" and it will work:

Import-csv $SelectedFile | Select -ExpandProperty EmailAddress | Tee-Object $UserMigrationLog -Append

Upvotes: 3

Related Questions