How do I remove all the groups from disabled Active Directory Users via Powershell?

  active-directory, ou, powershell, windows

Hey Guys so I’m trying to gather all the disabled users in our Active Directory and trying to remove the disabled users from all their groups. Mostly for cleanup purposes. I’m a bit stuck on my script. I’m not sure what to put after Remove-ADPrincipalGroupMembership

$disabled_users = Get-AdUser -SearchBase "Ou=Users, Ou=test, DC=testdomain, DC=io" -Filter
  "enabled -eq 'false'"
 foreach($person in $disabled_users) {
     Get-ADPrincipalGroupMembership $person | Remove-ADPrincipalGroupMembership #stuckhere
 }

Source: Windows Questions

LEAVE A COMMENT