1

I'm trying to use Powershell to select three columns with Import-Csv

Import-Csv $file Select-Object @{Name = "Joined"; Expression = {$_."Name" + " " + $_."Company" + " " + $_."Email"}}, *

I'm also trying to replace the field with the markup so Excel recognizes it as a link. Both of those things work on their own just fine. However, I'd like to insert the variables at the appropriate places in the mail hyperlink.

"=HYPERLINK(""mailto:mail@domain.com"",""John Doe"")"

Like

"=HYPERLINK(""mailto:$_.Email"",""$_.Name $_.Company"")"

When i try this i get all of the imported data not just the variables? I've tried escpaing the double quotes, using the ASCII code instead, is there a way to do this?

CSV

Supplier,Name,Email
AOL,John Jacobs,email@aol.com
Comcast,Ted Phillips,email@comcast.com
Bell,Jeff Heinz,email@bell.com
Verizon,Bill Mason,email@verizon.com
  • In short: In order to embed _expressions_ in an expandable string (`"..."`), you must enclose them in `$(...)`. Notably, this includes property and indexed access (e.g., `$($var.property)`, `$($var[0])`). Only variables _as a whole_ do not require this (e.g., `$var`, `$env:USERNAME`). See [this answer](https://stackoverflow.com/a/40445998/45375) to the linked duplicate. – mklement0 May 07 '21 at 22:59

0 Answers0