As anyone who has managed the Active Directory knows, if you delete an Active Directory object, although it marked as tombstoned, all the linked and non-linked attribute values are cleared. It is therefore difficult to reanimate the object because extra steps are required to recreate linked and non-linked attribute values.
In Windows Server 2008 R2, a new feature was introduced called the Active Directory Recycle Bin. If an object is placed in the AD Recycle Bin, reanimating this object is much simpler, because the linked and non-linked attribute values are retained.
You might be quick to say, "Hey, Let's active that feature right now". Well, there are two slight caveats. In order to use this feature, the domain must be in Windows 2008 R2 domain mode. Also, the forest must be in Windows 2008 R2 forest mode. If you have domain controllers in the forest that are not Windows 2008 R2, it will not be possible to make this change. As this feature can spare hours and hours of effort and downtime, you may want to start planning the migration of older servers.
The following steps outline bringing the domain and the forest to the Windows 2008 R2 native modes, and enabling the feature, using PowerShell.
Note: The next steps will cause irreversible changes to your forest and domain. You should make sure that you have backups from which you can perform an authoritative restore.
In order to raise the Forest and Domain Functional mode, we will need to start with installing the ActiveDirectory Module for Windows PowerShell.
(By default, Windows Powershell should already be pinned on the taskbar. Click the icon to launch)
1: Import-Module ActiveDirectory
1: (Get-ADDomain).DomainMode
1: Set-ADDomainMode -Identity yourdomain.com -DomainMode Windows2008R2Domain -Confirm:$false
1: (Get-ADForest).ForestMode
1: Set-ADForestMode -Identity yourdomain.com -ForestMode Windows2008R2Forest -Confirm:$false
After setting the Forest and Domain Functional mode, we now need to enable to AD Recycle Bin feature.
1: $cfgNameCtx = (Get-ADRootDSE).ConfigurationNamingContext
1: $recBin = "CN=Recycle Bin Feature,CN=Optional Features,"
2: $recBin = $recBin + "CN=Directory Service,CN=Windows NT,CN=Services,"
3: $recBin = $recBin + $cfgNameCtx
1: $target = (Get-ADDomain).Forest
1: Enable-ADOptionalFeature -Identity $recBin -Scope ForestOrConfigurationSet -Target $target -Confirm:$false
The following steps can be used to see how the new feature works with some test objects in an Organizational Unit. We will create an organizational unit and then create a few users and a group and add the users into the newly created group.
1: $defNameCtx = (Get-ADRootDSE).DefaultNamingContext
2: Set-Location ("AD:\" + $defNameCtx)
3: New-ADOrganizationalUnit -Name "Test Accounts"
1: Set-Location "ou=Test Accounts"
2: ForEach ($i in 1..100) { New-ADUser -Name ("User" + $i) }
1: New-ADGroup -Name GlobalSecGrp -GroupCategory Security -GroupScope Global
1: $users = Get-ADUser -Filter 'name -like "User*"'
2: Add-ADGroupMember GlobalSecGrp -Member $users
At this point, the Active Directory Recycle Bin should be enabled. Any directory objects, when deleted, are stored in the Recycle Bin. We will go ahead and delete the Test Accounts OU and delete all its contents.
1: Set-Location ("AD:\" + $defNameCtx)
2: $testAcctOU = Get-ADOrganizationalUnit -Filter 'name -like "Test Accounts"'
3: $testAcctOU | Set-ADOrganizationalUnit -ProtectedFromAccidentalDeletion $false
1: $testAcctOU | Remove-ADOrganizationalUnit -Recursive -Confirm:$false
Now that we have deleted the object, we can now demostrate how to restore the object.
2: $deletedOU = Get-ADObject -Filter 'name -like "Test Acc*"' -IncludeDeletedObjects
3: $deletedOU | Restore-ADObject
1: $deletedGrp = Get-ADObject -Filter 'name -like "GlobalSecGrp*"' -IncludeDeletedObjects
2: $deletedGrp | Restore-ADObject
1: $deletedUsers = Get-ADObject -Filter 'name -like "User*" -and isDeleted -eq $true' -IncludeDeletedObjects
2: $deletedUsers | Restore-ADObject
Launch the Active Directory Users and Computers tool and you should now be able to see all the users that were deleted. Also, if you look at the GlobalSecGrp and inspect its members, you should see all the deleted users as well.