How to cleanup AD using PowerShell
The following is a comparison between performing AD cleanup with Windows PowerShell and ADManager Plus:
Windows PowerShell
Steps to perform AD cleanup using PowerShell:
- Identify the domain in which you want to perform AD cleanup
- Identify the LDAP attributes you need identify the objects to be deleted.
- Compile the script.
- Execute it in Windows PowerShell.
Sample PowerShell script for deleting inactive computers:
Copied
ForEach ($Item in $Computers){
Remove-ADComputer -Identity $Item.DistinguishedName -Confirm:$false
Write-Output "$($Item.Name) - Deleted"
}
Click to copy entire script
ADManager Plus
Steps to perform AD cleanup:
For example: How to delete inactive computers in ADManager Plus
- Select Management -> Computer Management -> Delete Computers.
- Choose the domain and OU.
- Select the desired list of computers or import a CSV file, and click Apply.
Screenshot
» Start 30-day Free Trial
Following are the limitations to perform AD cleanup using native tools like Windows PowerShell:
- We can run this script only from the computers which have Active Directory Domain Services role.
- Troubleshooting is not easy in case of errors.
ADManager Plus can perform AD objects’ cleanup in bulk armed with just a CSV file from a simple and intuitively designed UI.