title: How to preserve spaces after a CSV import using a powershell script?
body: <p>I am currently working on a small PowerShell script that is supposed to split a CSV file with translations into individual files for the respective language. For this I use the <code>Import-Csv</code> cmdlet to import the source file, which has about this format:</p>
  <pre><code>ResourceId;GermanTranslation;EnglishTranslation;Check
  0;Deutscher Text;English text;OK
  1;  mit Leerzeichen  ;  with spaces  ;OK
  </code></pre>
  <p>The goal is to get a line-by-line representation of the translations in the format <code>ResourceId|EnglishTranslation|</code>. For this I have built the following script:</p>
  
  <pre class="lang-powershell prettyprint-override"><code>Set-Variable SOURCE_FILE -Option Constant -Value &quot;.\sourceFile.csv&quot;
  Set-Variable RESULT_FILE -Option Constant -Value &quot;.\resultFile.csv&quot;
  
  foreach ($row in (Import-Csv -Path $SOURCE_FILE -Delimiter &quot;;&quot;)) {
      Add-Content -Path $RESULT_FILE -Value ($row.RessourceId + &quot;|&quot; + $row.EnglishTranslation + &quot;|&quot;)
  }
  </code></pre>
  <p>Basically, everything works as desired, but when I examined the results, I noticed that the spaces with which some elements begin were no longer present in the result:</p>
  <pre class="lang-powershell prettyprint-override"><code>0|English text|
  1|with spaces  |
  </code></pre>
  <p>Unfortunately I didn't find a parameter in <a href="https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/import-csv?view=powershell-7.1#parameters" rel="nofollow noreferrer">the MS documentation</a> that addresses this problem, so I was unsure at first.
  After that, I took a look at <a href="https://www.rfc-editor.org/rfc/rfc4180#page-3" rel="nofollow noreferrer">RFC 4180</a>, which describes the CSV file format more or less exactly. It states that spaces <em>should</em> be considered as part of a field and not ignored. <em>Should means not must,</em> so it may well be that there really is no option for this.</p>
  <p>Is there a possibility to preserve the spaces without me having to parse the whole file on my own?</p>