title: Add users with Active Directory email attribute to a group which contains "@abc.com"
body: <p>We have the ticketing system to create Window ID for the new joiner, we need to add the new user to a specific grouping depends on their email domain. </p>
  
  <p>For example if the user's e-mail address is <code>thomas@abc.com</code>, it will check if the email address contains <code>@abc.com</code>, then add it to the <code>test_group</code>; if the user in the group, skip this step.</p>
  
  <pre><code>$Users = Get-ADUser -Filter * -Properties emailaddress
  
  foreach ($user in $Users)
  {
      if ($user.emailaddress -match "abc.com") 
      {
              $GroupMembers = Get-ADGroupMember -Identity "test_group" | Select -ExpandProperty SamAccountName
              if ($User.SamAccountName -NotIn $GroupMembers)
              {
              Add-ADGroupMember -Identity "test_group" -Members $User
              }
          }
      }
  </code></pre>
  
  <p>But after I execute, I got hit error as below</p>
  
  <blockquote>
    <p>You must provide a value expression on the right-hand side of the '-' operator.<br>
    At line:9 char:42</p>
    
    <p>Unexpected token 'NotIn' in expression or statement.<br>
    At line:9 char:43</p>
    
    <p>Unexpected token 'GroupMembers' in expression or statement.<br>
    At line:9 char:49</p>
  </blockquote>
  
  <p>Thank you very much for the help in advance.</p>