Remove a security group from all objects in an OU

TJCooper 1 Reputation point

I need to remove a security group from all objects in an OU. What is the most efficient way to do this? Pull all objects in an OU, then do a loop that goes through each ACL and checking for the group and then remove it?

Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
4,867 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. チャブーン 81 Reputation points MVP

    Hi, TJCooper

    This is Chaboon.

    I seem it is simplest solution, you use New-PSDrive with PowerShell, connecting Active Directory.

    see Below the code:

    Import-Module ActiveDirectory
    New-PSDrive -name MyAD -psprovider ActiveDirectory -Root "OU=Target,DC=example,DC=com" -server
    cd MyAD:
    $Groups = Get-ChildItem | Where {$_.objectClass -eq "Group"}
    # if you want to find recursive objects
    # $Groups = Get-ChildItem -recurse | Where {$_.objectClass -eq "Group"}
    ForEach ($Group in $Groups) {Write-Host $Group is delete! ; Remove-ADGroup $Group -confirm:$false}
    0 comments No comments