title: Treat string like it is a piece of code in PowerShell
body: <p>In PowerShell, I would like to read a CSV file, get all column names and dynamically pass them to a for loop, to select items on each row, for each column name. To do so, I have the following script:</p>
  <pre><code>$CSV_Employees = Import-Csv &quot;C:\Users\L_L\Desktop\Employees_v2.csv&quot;
  
  $output_array = @()
  foreach($HEADER in $CSV_Employees[0].psobject.properties.name){
      $output_array += $HEADER
  }
  
  $output_array = $output_array | ForEach-Object {'''$($' + &quot;LINE.$_&quot;} 
  $output_variable= $output_array-join &quot;)', &quot;
  $output_variable= &quot;&quot;&quot;(&quot; + $output_array + &quot;)')&quot;&quot;&quot;
  
  foreach($LINE in $CSV_Employees){
     $output_variable
  }
  </code></pre>
  <p>Output:</p>
  <p>&quot;('$($LINE.Id)', '$($LINE.FirstName)', '$($LINE.LastName)', '$($LINE.Salary)', '$($LINE.Department)', '$($LINE.Country)')&quot;</p>
  <p>&quot;('$($LINE.Id)', '$($LINE.FirstName)', '$($LINE.LastName)', '$($LINE.Salary)', '$($LINE.Department)', '$($LINE.Country)')&quot;</p>
  <p>&quot;('$($LINE.Id)', '$($LINE.FirstName)', '$($LINE.LastName)', '$($LINE.Salary)', '$($LINE.Department)', '$($LINE.Country)')&quot;</p>
  <p>&quot;('$($LINE.Id)', '$($LINE.FirstName)', '$($LINE.LastName)', '$($LINE.Salary)', '$($LINE.Department)', '$($LINE.Country)')&quot;</p>
  <p>&quot;('$($LINE.Id)', '$($LINE.FirstName)', '$($LINE.LastName)', '$($LINE.Salary)', '$($LINE.Department)', '$($LINE.Country)')&quot;</p>
  <p>&quot;('$($LINE.Id)', '$($LINE.FirstName)', '$($LINE.LastName)', '$($LINE.Salary)', '$($LINE.Department)', '$($LINE.Country)')&quot;</p>
  <p>The problem that I am looking to solve is within the foreach loop at the end. It just prints the content of the variable that I am passing. I know that this is the usual behavior but is it possible to treat this variable like an actual piece of code?</p>
  <p>The end goal is to create a SQL INSERT INTO statement out of a CSV file. This exact piece is the one that would create the VALUES section of the INSERT INTO statement with all rows of the data from the CSV file. This needs to work for different CSV files, so the column names can't be fixed.</p>
  <p>I am using a sample data, which looks like this:
  <a href="https://i.stack.imgur.com/kT13t.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kT13t.png" alt="enter image description here" /></a></p>