Skip to content

NKCODE TECH GEEK ZONE

  • RSS - Posts
Menu
  • Home
  • Cloud
    • Azure
    • Alibaba
    • AWS
  • Hardware
  • Linux
  • Network
  • Security
  • Windows Client / Servers
    • SQL
    • Windows Client OS
      • Windows 10
    • Windows Servers
      • Windows 2008R2
      • Windows Server 2012R2
      • Windows Server 2016
      • Windows Server 2019
  • VMWARE
  • Free Tools
  • About Me
    • Disclaimer
Menu

Enable Active Directory Recycle Bin & Restore Deleted Objects

Posted on January 5, 2013

Once you have installed Windows 2008 R2 on all Domain Controllers and the Forest Functionality mode is set to Windows 2008 R2, the Recycle Bin is an available option. However, it is not automatically enabled.  In order to use it, it has to be enabled first.

Here’s the Powershell command (all one line) to run as an Enterprise Admin:

import-module activedirectory ;
Enable-ADOptionalFeature –Identity ‘CN=Recycle Bin Feature,CN=Optional Features,CN=Directory Service,CN=Windows NT,CN=Services,CN=Configuration,DC=Domain,DC=COM’ –Scope ForestOrConfigurationSet –Target ‘Domain.COM’

Once the AD Recycle Bin is enabled, Powershell commands provide access to it (along with other methods).

PowerShell Command to change the tombstone lifetime. This example changes it  to 365 days (1 year):

Set-ADObject
-Identity “CN=Directory Service,CN=Windows NT,CN=Services,CN=Configuration,DC=Domain,DC=COM” –Partition “CN=Configuration,DC=Domain,DC=COM” –Replace:@{“tombstoneLifetime”=365}

PowerShell Command to change the deleted object lifetime. This example changes it  to 365 days (1 year):

Set-ADObject
-Identity “CN=Directory Service,CN=Windows NT,CN=Services,CN=Configuration,DC=DOMAIN,DC=COM” –Partition “CN=Configuration,DC=DOMAIN,DC=COM” –Replace:@{“msDS-DeletedObjectLifetime”=365}

This Microsoft article provides additional information on restoring deleted objects using the recycle bin.

Here’s an example of what the Microsoft Article describes.
Find all deleted computers:

$DeletedComputers = Get-ADObject -SearchBase “CN=Deleted Objects,DC=DOMAIN,DC=COM” -Filter {ObjectClass -eq “computer”} -IncludeDeletedObjects -Properties lastKnownParent

Find all deleted users:

$DeletedUsers = Get-ADObject -SearchBase “CN=Deleted Objects,DC=DOMAIN,DC=COM” -Filter {ObjectClass -eq “user”} -IncludeDeletedObjects -Properties lastKnownParent

Once you have discovered the deleted objects, it is trivial to restore them:

$DeletedComputers | Restore-ADObject

$DeletedUsers | Restore-ADObject

Did you delete a bunch of users on a specific date and need to recover (undelete) them?
Try this:

$ChangeDate = Get-Date (“9/6/2011″)
Get-ADObject -Filter { (whenChanged -eq $changeDate) -and (isDeleted -eq $true) -and (name -ne “Deleted Objects”)  -and (ObjectClass -eq “user”) } -IncludeDeletedObjects -Properties * |  Restore-ADObject

Use Get-Help Get-ADObject for additional information on finding deleted objects. Hint: You can also filter on the IsDeletedattribute just remember the  -IncludeDeletedObjects parameter.

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pinterest (Opens in new window) Pinterest
  • Click to share on Telegram (Opens in new window) Telegram
  • Click to share on WhatsApp (Opens in new window) WhatsApp
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

1 thought on “Enable Active Directory Recycle Bin & Restore Deleted Objects”

  1. Mohamed Naflan says:
    January 18, 2014 at 4:08 pm

    Lot of tahnx sir

Comments are closed.

Welcome to Teck Geek Zone

Alibaba & Azure Cloud with a free trial worth $200-1200 USD Click below Cloud Providers

  • Securing Your Cloud Environment with Alibaba Cloud Firewall
  • 🚢 Sailing into the Data Age: How Cloud and IoT are Revolutionizing the Marine Industry
  • What is Azure Grafana? A Comprehensive Guide to Monitoring and Visualization
  • 🔐 How to Enable Virtualization-Based Security (VBS) for Windows Workloads in VMware Cloud Foundation and vSphere
  • Microsoft’s Azure SRE Agent: AI-Powered Reliability Engineering

Categories

  • Cloud (186)
    • Alibaba (39)
    • AWS (39)
    • Azure (114)
  • Free Tools (5)
  • Hardware (17)
  • Linux (13)
  • Network (28)
  • Security (21)
  • VMWARE (54)
  • Windows OS (44)
    • Windows 10 (7)
  • Windows Servers (69)
    • SQL (3)
    • Windows 2008R2 (7)
    • Windows Server 2012R2 (15)
    • Windows Server 2016 (20)
    • Windows Server 2019 (10)

Subscribe to our newsletter

©2025 NKCODE TECH GEEK ZONE | Design: Newspaperly WordPress Theme
%d