title: pull only user name and select groups from AD with Power shell
body: <p>I want to get all the users in my OU and list only the names of the users that are a member of any group with the word managers in it and list that group or groups they belong to.</p>
  
  <p>So for example </p>
  
  <p>TSmith
  Equipment managers
  Managers night shift</p>
  
  <p>Bkline
  Equipment managers Day Shift</p>
  
  <p>I have been trying to tweak the below script.
  The issue is if the user is a member of any group with managers in the name it list everything about that user.  All the groups the last log on time everything in AD.</p>
  
  <p>Thanks so much for any help.</p>
  
  <pre><code>  Import-Module ActiveDirectory
    $users = Get-ADUser -searchbase "OU=East,DC=CHM,DC=com" -Filter * -Properties * 
    foreach ( $user in $users ) {
    $user
        $groups = $user | select -ExpandProperty memberof
  
        if ($groups -match 'manager') {
            $user.samaccountname
            $groups
            }
  } 
  </code></pre>