title: compare and diff files in Powershell
body: <p>I have two text files, one named “master.txt” and other “slave.txt”. Each text files contains a set of users as below, and I wanted to compare master.txt file with slave.txt file and report the missing ones in the slave.txt file. In the current result, it seems both the files are compared and responds back missing ones across both the files. Could someone help me please?</p>
  
  <pre><code>~]# cat master.txt
  user1
  user2
  user3
  
  ~]# cat slave.txt
  user2
  user4
  </code></pre>
  
  <p>Script:</p>
  
  <pre><code>$mfile = Get-Content "C:\master.txt"
  $sfile = Get-Content "C:\slave.txt" 
  foreach ($mobj in $mfile) {
  
  foreach($sobj in $sfile){
          if ($mobj -ne $sobj) {
          Write-Output "$mobj is Not Found:"
          }
       }
  }
  </code></pre>
  
  <p>Current result:</p>
  
  <pre><code>user1 is Not Found:
  user1 is Not Found:
  user2 is Not Found:
  user3 is Not Found:
  user3 is Not Found:
  </code></pre>
  
  <p>Expected result (these are the ones present in master.txt but not in slave.txt):</p>
  
  <pre><code>user1 is Not Found:
  user3 is Not Found:
  </code></pre>