This PowerShell script detects and cleans up lingering objects in an Active Directory domain. It checks for lingering objects on all domain controllers in the current Active Directory domain and offers an optional -CheckOnly
switch that allows you to check for lingering objects without removing them.
- PowerShell 5.1 or later
- Active Directory module for PowerShell
- Administrator privileges to run the script
-
Download the
LingeringObjectsCleanup.ps1
script from this repository. -
Open a PowerShell console with administrator privileges.
-
Navigate to the directory where the script is saved.
-
Run the script with the desired mode:
To check for lingering objects without removing them, run the following command:
.\LingeringObjectsCleanup.ps1 -CheckOnly
To remove lingering objects from all domain controllers in the current Active Directory domain, run the following command:
.\LingeringObjectsCleanup.ps1
- This script requires the Active Directory module for PowerShell to be installed. If the module is not installed, the script will attempt to import it.
- Make sure to run the script with administrator privileges, as it requires elevated permissions to perform the cleanup tasks.