title: How to display just the group name of groups user is member of in powershell
body: <p>So I have the following script but it lists the full name of the AD group. (e.g. <code>CN=GroupName,OU=OUName,DC=DomainName,DC=com</code>) How do I specify only the group's name, so that it lists only the name itself. The part after <code>CN=</code>. I tried <code>$group.Name</code> but no such luck.</p>
  
  <pre><code>Import-Module ActiveDirectory
  $userlist = Get-Content "C:\Scripts\US_User_List.txt"
  
  foreach ($username in $userlist) {
      $grplist = (Get-ADUser $username –Properties MemberOf | Select-Object MemberOf).MemberOf
      foreach ($group in $grplist) {
          write-host $group
      }
  }
  </code></pre>
  
  <p>Also as a second question is there some way to filter based on what the group name starts with?</p>