Active Directory
A set of directory-based technologies included in Windows Server.
6,405 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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?
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 dc00.example.com
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}