title: AD Query into .txt file to remove line in .csv of existing users
body: <p>I am using a piece of code here that uses a Master.txt file with a list of usernames, it queries Active Directory and checks if they are a user or not. Afterwards it populates two seperate .txt files called UserExists and UserDoesntExist.</p>
  <pre><code>$Users = Get-Content &quot;Desktop\Master.txt&quot;
  ForEach ($User in $Users)
  {
      $UserObj = $(try {Get-ADUser $User} catch {$Null})
      If ($UserObj -ne $Null)
      {
         Write-Host &quot;$User Exists&quot; -BackgroundColor Green -ForegroundColor Yellow
         Add-Content 'Desktop\UserExists.txt' &quot;$User&quot;
      }
      else
      {
         Write-Host &quot;$User Doesn't Exist&quot; -BackgroundColor Red -ForegroundColor Yellow
         Add-Content 'Desktop\UserDoesntExist.txt' &quot;$User&quot;
       }
  }
  </code></pre>
  <p>The two lists work fine as expected, there is also a .csv file that contains every user on the master.txt file but with headers in for Password etc and other fields for user creation further down the line. But I'd like to remove the line in the.csv where the user already exists based on a .txt file. Is there a way to read the .txt document of UserExists and then look up the matching Username in the .csv and remove the line? This is a field in both the .csv and .txt file so it would match. Is this doable? Any help and advice would be really appreiciated.</p>