title: Powershell - Remove-ADGroupMember
body: <p>I'm trying to remove the groups from users in other domain.</p>
  
  <p>Example: Me as admin wants to disable an user and remove his groups in other domain.</p>
  
  <p>The problem is I don't know how to use <code>Remove-ADGroupMember -Server</code> in <code>Foreach</code> loop, if I don't use <code>Foreach</code> I can use the <code>-Server</code> option.</p>
  
  <p>Error of Remove-ADGroupmember:<br>
  <a href="https://i.stack.imgur.com/5L22E.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5L22E.png" alt="Error of Remove-ADGroupmember"></a></p>
  
  <p>How can I get <code>-Server</code> property within <code>Foreach</code>?</p>
  
  <pre><code>$groups = (Get-Aduser -server ServerY -Identity manusys -Properties MemberOf).memberof
  
  Foreach ($group in $groups) {
      Remove-ADGroupMember -identity $group -Members manusys -Confirm:$false -ErrorAction:SilentlyContinue
  }
  </code></pre>
  
  <p>The user account <code>Manusys</code> has these groups:</p>
  
  <pre>
  CN=NO_CamerasAlertMGR,OU=Ordinary Distribution Lists,OU=Distribution Lists,DC=test,DC=com
  CN=NO_CamerasAlertCM,OU=Ordinary Distribution Lists,OU=Distribution Lists,DC=test,DC=com
  CN=NO_CamerasReport,OU=Ordinary Distribution Lists,OU=Distribution Lists,DC=test,DC=com
  CN=NO_CamerasReport_CM,OU=Ordinary Distribution Lists,OU=Distribution Lists,DC=test,DC=com
  CN=NO_CamerasReport_MGR,OU=Ordinary Distribution Lists,OU=Distribution Lists,DC=test,DC=com
  </pre>