2

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?

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

2 Comments

Oh right. As simple as that! Excuse my ignorance but why does removing the subexpression change this?
Using a subexpression $() within a string "" will cast the result of that subexpression to a single string

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.