title: Is there a way to force powershell -Export-CSV cmdlet to maintain a specific column order?
body: <p>I'm new to powershell, so the script is a Frankenstein of various examples of from sites.</p>
  
  <p>My question is how can I make sure that a csv file I am creating for a DataTable keeps the column order I specify?</p>
  
  <p>My script does this to populate the csv headers and values like so:</p>
  
  <pre><code>...snip...
  $dataTable | ForEach-Object {
              $csv+=New-Object PSObject -Property @{
                  program_code=$_.ProgramCode;
                  first_name=$_.FirstName;
                  last_name=$_.LastName;
                  email=$_.email;
                  phone=$_.phone;
                  phone2=$_.otherphone;
                  address=$_.addr1;
                  address2=$_.addr2;
                  city=$_.city;
                  state=$_.state;
                  postal_code=$_.Zip;
                  country=$_.Country;
                  grad_year=$_.HsGradDate;
                  lead_date=$_.LeadDate;
                  lead_source=$_.LeadSource;
                  school_status=$_.SchoolStatus;
          }
          }
      $csv | Export-CSV C:\scripts\NewLeads$(Get-Date -Format yyyyMMdd).csv -notype -Append
  ...snip...
  </code></pre>
  
  <p>I want the file to have to columns in the order that I specify in the script, but when I open it in notepad or excel the columns appear in a seemingly random order. Keyword being seemingly since they may have some method of ordering themselves.</p>