0

I am importing and exporting csv files with powershell. I am trying to rename a csv column to include the name of the current week. I am recording the current week in a variable ReportWeek. When the new csv is created, it is adding the text verbatim to the column name instead of using the variable value

Import-Csv $file| Select-Object Name,QA_Level,Team,@{Name= 'Wk + $ReportWeek Lines';Expression={$_.'Lines Typed'}} | Export-csv $pathtofiles\temp\Filename_temp.csv -NoTypeInformation

This is the what the header is written as Wk + $ReportWeek Lines

I would like it to be Wk 2 Lines

  • 2
    Single quotes prevent variable expansion. => `'Wk' + $ReportWeek + 'Lines'` – Santiago Squarzon Jan 12 '22 at 03:35
  • 2
    Swap the single quotes for double; string "*interpolation*" can only happen within double quotes, as single quotes print verbatim. – Abraham Zinala Jan 12 '22 at 03:36
  • 3
    In short: Only `"..."` strings (double-quoted, called _expandable strings_) perform string interpolation (expansion of variable values) in PowerShell, not `'...'` strings (single-quoted, called _verbatim strings_): see [this answer](https://stackoverflow.com/a/40445998/45375) for an overview of PowerShell's _expandable strings_ and [this answer](https://stackoverflow.com/a/55614306/45375) for an overview of PowerShell's _string literals in general_. – mklement0 Jan 12 '22 at 03:39

0 Answers0