title: How to compare the results of Get-ADUser?
body: <p>I have the results of two <code>Get-ADUser</code> queries stored in variables (they are querying two Active Directories).</p>
  
  <p>What is the best way to compare them looking for an specific attribute and export to a CSV if they match? I tried to get it to work using nested <code>forEach</code> loops and comparing attributes with an <code>if</code> but it just appended to the csv all the results from both AD.</p>
  
  <p>I am not currently home and I will upload my current code when I arrive but in pseudocode it was like this:</p>
  
  <pre class="lang-cs prettyprint-override"><code>$res1 = get-adUser -filter{enabled -eq $true} -Properties     samAccountName, displayname, mail | select-object samAccountName, displayname, mail
  $res2 = get-adUser -server ABC -filter{enabled -eq $true} -Properties samAccountName, displayname, mail | select-object samAccountName, displayname, mail
  
  ForEach($u1 in $res1){
    ForEach($u2 in $res2){
      If($u1.mail -eq $u2.mail){
        Write-host $u1.mail $u2.mail
      }
    }
  }
  </code></pre>