title: Powershell Compare-Object Format Output
body: <p>Here is the script that I wrote:</p>
  
  <pre><code>function Compare {
  
      $file1 = Read-Host "Please enter the path of the first file you would like to compare"
      $file2 = Read-Host "Please enter the path of the second file you would like to compare"
  
      $outFile = Read-Host "Please enter the path to where you would like your output file."
  
      Try{
          $compareOne = Get-Content $file1
          $comparetwo = Get-Content $file2
      } 
      Catch{
          Write-Host "The path you entered is either invalid or the file does not exist. "    
      }
  
      Write-Host "Beginning comparison"
      Compare-Object $compareOne $compareTwo  | Out-File $outFile
      Write-Host "Complete!"
  }
  
  Compare
  </code></pre>
  
  <p>And this is my output:</p>
  
  <pre><code>InputObject | SideIndicator
  ------------|--------------
     Value1   |    &lt;=
     Value2   |    &lt;=
     Value3   |    =&gt;
     Value4   |    =&gt;
  </code></pre>
  
  <p>Is it possible for me to format my output in such a way that I can change the headers of each column?</p>
  
  <p>And instead of <code>=&gt;</code> and <code>&lt;=</code> I could give which file the differences are actually found in? </p>
  
  <p>Here is the kind of output I am looking for: </p>
  
  <pre><code>   Value    |     File 
  ------------|--------------
     Value1   |    $file1
     Value2   |    $file2
     Value3   |    $file2
     Value4   |    $file1
  </code></pre>
  
  <p>I'm still quite new to PowerShell so if you could explain your answer that would be great, just so I can understand what is actually going on.  </p>
  
  <p>I am also trying to make this "dummy proof" so that anyone can just compare two text files, without any further input. </p>
  
  <p>Any help would be greatly appreciated!</p>