title: powershell - is it possible to create a text file with header fields and align the fields of every inserted line with its corresponding header field?
body: <p>I've made a powershell script that first creates a text file (providing it doesn't already exist) with a line containing 2 header fields, "NAME" and "SURNAME" separated by a few whitespaces. </p>
  
  <p>It will then prompt the user to insert a name and a surname, both of which will be written as a new single line to the text file, underneath the header line. The user doesn't need to insert more name-surname lines but the idea is to create a few more of these lines. </p>
  
  <p>However, I have no idea about how to align every inserted surname with the "SURNAME" header field. By "align" I mean the first letter of every surname be in the same column as the "S" of "SURNAME" (the explanation may not be necessary but just in case...)</p>
  
  <p>Anyway, here's the code:</p>
  
  <pre><code>clear
  
  [string]$name=read-host -prompt "Enter the name"
  [string]$surname=read-host -prompt "Enter the surname"
  [string]$header="NAME        SURNAME"
  [string]$line="$name        $surname"
  
  add-content -value $header -path c:\data.txt
  add-content -value $line -path c:\data.txt
  $answer=read-host -prompt "¿Would you like to keep inserting name-surname pairs? (yes/no)" 
  
  while ($answer -eq "yes") {
  
    $name=read-host -prompt "Enter the name"
    $surname=read-host -prompt "Enter the surname"
    $line="$name       $surname"
    add-content -value $line -path c:\data.txt
    $answer=read-host -prompt "¿Would you like to keep inserting name-surname pairs? (yes/no)" 
  }
  
  get-content -path c:\data.txt  
  </code></pre>