Summery
The Active Directory Recycle Bin is an AD feature that allows administrators to restore deleted directory objects, such as users, groups, and computers, without recreating them manually.
When an AD object is deleted:
- Recycle Bin enabled: The object becomes a deleted object but retains most of its attributes, including group memberships and permissions. It can be restored with its original attributes.
- Recycle Bin disabled: The object typically becomes a tombstone, retaining fewer attributes. Restoration is more limited.
A tombstone in Active Directory is a record marking an object that has been deleted. AD keeps it temporarily so that all domain controllers can learn about the deletion through replication.
When recycle bin is enabled, deleted object usually stay for around 180 days in the domain or 60-180 for when it’s disabled before they are terminated for good.
It all depends on the retention policy in place.
Commands
Enumeration
Get-ADOptionalFeature -Filter 'Name -like "Recycle Bin Feature"' - Check whether the recycle bin feature is enabled
Get-ADObject -Filter 'isDeleted -eq $true' -IncludeDeletedObjects -Properties * - Find all deleted objects
Get-ADObject -Filter 'isDeleted -eq $true -and objectClass -eq "user"' -IncludeDeletedObjects - Find just deleted users
Restoration
Restore-ADObject -Identity "<GUID>" - Restore a deleted object with its GUID
Get-ADObject -Filter 'objectSid -eq "<SID>"' -IncludeDeletedObjects | Restore-ADObject - Restore a deleted object with its SID
Deletion
Remove-ADUser -Identity "john.doe" - Delete an object
Remove-ADObject -Identity "<ObjectGUID>" -IncludeDeletedObjects -Confirm:$false - Permanently remove a deleted object
Examples
Used in TombWatcher:
Get-ADObject -Filter 'isDeleted -eq $true' -IncludeDeletedObjects -Property * - See into the AD recycle bin
$deleted = Get-ADObject -Filter 'objectSid -eq "S-1-5-21-1392491010-1358638721-2126982587-1111"' -IncludeDeletedObjects and Restore-ADObject -Identity $deleted - Restore an account
Get-ADObject -Filter 'objectSid -eq "S-1-5-21-1392491010-1358638721-2126982587-1111"' -IncludeDeletedObjects | Restore-ADObject - Restore and account
Used in Cascade:
Get-ADObject -IncludeDeletedObjects -Filter 'isDeleted -eq $true' -Properties * Shows all deleted objects
Restore-ADObject -Identity f0cc344d-31e0-4866-bceb-a842791ca059 - Restore an object
Get-ADObject -Filter 'objectSid -eq "S-1-5-21-3332504370-1206983947-1165150453-1136"' -IncludeDeletedObjects | Restore-ADObject - Restore an object
Used in Voleur:
Get-ADOptionalFeature 'Recycle Bin Feature' - Check whether the Recycle Bin feature is enabled
References
Used in: TombWatcher, Cascade, Voleur
Similar note: Windows recycle bin