05 February, 2012

How to Recover Deleted Objects Using AD Recycle Bin

Now since AD Recycle Bin has been enabled, Let see if it actually work... No I am not at all doubting Microsoft, but as I have said in my earlier post about human tendency to explore... :)

So let`s Explore....

I have an OU "HR" in which I have two users "User1" and "User2". Both the users are member of groups "Domain Users" and "HR Group"


Deleting the OU "HR"....


Warning!!!!


Gone.....


Lets check if the OU and the Users inside that OU has actually been deleted. We can check this by running the following Powershell Command:-

Get-ADObject -SearchBase "CN=Deleted Objects,CN=Lab,DC=Com" -ldapFilter "(ObjectClass=*)" -includeDeletedObjects | Format-List Name,ObjectClass,ObjectGuid



And here we go.... I can see the OU "HR" and the Users "User1" & "User2" which were in that OU


One more simple command to restore the User...

Restore-Object -identity <Object GUID>

The GUID is of the deleted object which you wants to restore and you can get the GUID from the above command that we just ran.


Let me restore User1 whose GUID starts with f7d46783...


Error.... OMG

The Error in RED says something about "Objects Parent is either uninstantiated or deleted". Is it trying to say that the OU (HR) in which the User1 which I am trying to restore is also deleted... :)


So lets first restore the OU "HR"


Done...So the Parent (OU=HR) has been restored... But remember, this will not automatically restore the users inside it...


Now restore the User as well



User1 is back in action...


And the best part is.. That's the User1 is back with all the attributes as opposed to being restored with partial attributes when restoring using LDP/ADRestore


Another OU in the process of getting deleted.... But with around 100 users...


Deleting....


Warning!!!!


Gone...


Now do you think I am going to sit here and restore all the 100 users one by one and will show you the pictures of the restoration of all the 100 users.... Wish I had all that time...But I don't have and moreover, when Microsoft have an option to restore the objects in bulk, then why not make use of it and save time...

Remember, Time Is Money.. :)

We will run the following command to list all the users which were in the OU=Production

Get-ADObject -ladapFilter "(lastknownParent=OU=Production,DC=Lab,DC=Com)" -includeDeletedObjects



Nothing happened??


Let me run the same command that we ran few slide back to see if the data is in Deleted Objects Container


hmm.. Strange.. The data is there in the Deleted Objects container.. Then why isn't it is getting displayed when I ran the command

Get-ADObject -ladapFilter "(lastknownParent=OU=Production,DC=Lab,DC=Com)" -includeDeletedObjects



Lets read the command again "Carefully"

So, you are asking Powershell to display you the objects whose LastKnownParent is "Production"... But where do we have Production OU in AD... Is it not DELETED... :)



Find Find.... Production OU is not in AD.... If you are not able to find that OU in AD then how can you expect Powershell to find it!!!


So here is the Production OU in the Deleted Objects Container


Lets first restore the OU=Production...



Restored!!!


Now lets run the command again

Get-ADObject -ladapFilter "(lastknownParent=OU=Production,DC=Lab,DC=Com)" -includeDeletedObjects



Here we go....


Once displayed, now we will restore all the objects in one go...

Get-ADObject -ladapFilter "(lastknownParent=OU=Production,DC=Lab,DC=Com)" -includeDeletedObjects | Restore-ADObject




Wow......