title: See if a any of a list of users, is a member of an AD group
body: <p>I have a list of Users and a list of AD Groups. I would like to know, if any of the users are a member of those groups. </p>
  
  <ul>
  <li>I do not need to know which members are a member of which group.  </li>
  <li>I just need to know if ANY user matches a Group, if a match exists
  output Match found and group name.</li>
  </ul>
  
  <p>I have got this code:</p>
  
  <pre><code>$users = Get-Content C:\test\testusers.csv
  $groups = Get-Contect C:\test\testgroups.csv
  foreach ($user in $users) {
      foreach ($group in $groups) {
          $members = Get-ADGroupMember -Identity $group -Recursive |
                     Select -ExpandProperty SamAccountName
          if ($members -contains $user) {
              Write-Host "Match Found $group"
          }
      }
  }
  </code></pre>
  
  <p>I have run this against a test of 4 users and 3 ad groups, whilst this gives me what I need. I get the output:</p>
  
  <ul>
  <li>Match Found Groupname 1</li>
  <li>Match Found Groupname 2</li>
  <li>Match Found Groupname 1</li>
  </ul>
  
  <p>My understanding is that this is scanning each user against all groups, then the next user against all groups. Whilst this worked for my test batch in small numbers, I need to scan 2000 users against 1100 groups.</p>
  
  <p>I take it this is because I am scanning the users against groups? and need to scan groups for users?</p>
  
  <p>Is there a way I can put a line of code that says, if found move to next group?</p>