title: Remove group membership in AD Powershell script
body: <p>I need to remove the groups in the "member of" section of users in a dead accounts OU.</p>
  
  <p>The script runs and receives no errors, but the items in the list have not changed at all.</p>
  
  <pre><code>#Choose Organizational Unit
  $SearchBase = "OU=Dead Accounts,DC=domain,DC=domain,DC=COM"
  #Choose filtering parameters
  $disabledaccounts = $SearchBase.children  
  #Search through each item and perform x
  foreach ($userObject in $disabledaccounts){  
          foreach ($group in $userObject.memberof)  
              {  
                  $group = [ADSI]"LDAP://$group"  
                  $group.remove("LDAP://$($userobject.distinguishedName)")   
              }} 
  </code></pre>
  
  <p>Doesn't seem to be working in my environment, though.</p>
  
  <p>What is an easier way to write this, and can someone explain the bottom part? (group = [ADSI]"LDAP://$group" etc..)</p>