title: Check for user in a group in a different domain
body: <p>I am stuck with a piece of code.
  We have 2 AD domains with users and groups in them. 
  I am trying to run a script that will check if the user is a member of a group to disable EV access and if they are not a member of that group add them to the EV enable group. </p>
  
  <p>I have this working for 1 domain but I can't get it to work across the 2 domains we have.
  I want the script to check domain1 and add it to the group in domain1 but if it doesn't find the user check domain2 and add it to the group in domain2.</p>
  
  <p>Below is an extract of the code I have but I am struggling to get it to recognise the domain controller so that it looks in the right domain for the user.</p>
  
  <pre><code>    foreach ($u in $Users){
  Foreach($domain in $Domainlist)
      {
      $dom =get-addomain $domain.name
      $dm = $dom.distinguishedname
      $dname = $dom.name
      $DomName = $dom.DNSRoot
      $ADdc = Get-addomaincontroller -discover -domain $domName
      $dc = $ADdc.hostname
      $User = Get-ADUser $u.name -server $dc 
      $Enablegroup = "cn=evenable,ou=users and computers," + $dom 
      $disablegroup = "cn=evdisable,ou=users and computers," + $dom    
  
          if ((Get-ADUser $u.name -server $dc -Properties memberof).memberof -eq $disablegroup)
          {
          $name = $u.name
          $dm = $domain.name
          Write-host "$name is a member of the $dm EV disable group" -f Yellow
          }
  </code></pre>