Wednesday 22 June 2016

How to restore a deleted object in active directory 2008 R2 and Activie Directory 2016 and Exchange Server

If you have deleted any AD object unexpectedly and want to restore it. If you have already enabled the ADRecycleBin then you can do it with the following steps.

First let's check if your recycle bin is enabled or not.
you can check with the following command
Get-ADOptionalFeature -Identity 'Recycle Bin Feature'

The above command will show the complete detail of recycle bin.

Let's it was enabled then you can use the following command to first find the deleted object.
you can use the following to display the deleted object first.
Get-ADObject -Filter {displayName -eq "DisplayNameOfUser"} -IncludeDeletedObjects
or
Get-ADObject -Filter {samaccountname -eq "nawaz.nawaz"} -IncludeDeletedObjects

Now it should show the deleted object to you.
let's you have found the deleted object and now want to restore.

you can use the following command to restore that ID.

Get-ADObject -Filter {displayName -eq "DisplayNameOfUser"} -IncludeDeletedObjects | Restore-ADObject


Note: you may need to add the target path as well in AD 2016, so you may use the following command.

Get-ADObject -Filter {UserPrincipalName -eq "nawaz@domain.com"} -IncludeDeletedObjects | Restore-ADObject -TargetPath "OU=Users,OU=HR,OU=Managementname,DC=domain,DC=com"

Note: if this AD Object/ID have any mailbox then that will be automatically recovered with out any issue. just wait for few minutes.
P.S: Will be better if just copy/past the displayname of the user object to be restored. As it is case sensitive. and the result would not display if you typed lower character instead of upper character. 

No comments:

Post a Comment