Restore AD Account

| February 25th, 2018

Every Active Directory Admin has done it.  Delete a user (or users), and for one reason or another you need them back.  Well, there’s a solution in the Active Directory Reycle Bin.

This feature should have been thought of a long time ago, but it’s been around long enough now that I can’t really complain too much.  Its very simple to use (once it’s enabled), and saves a ton of time that you would otherwise be using to re-create, or restore the accounts from a backup of some kind.

Now, I’m not going to get into how to enable this feature.  I reserve this blog for quick posts, with simple commands or scripts that you can start using right away.  If you do a search for how to enable it, I guarantee you’ll find a number of websites with screenshots to guide you through it.

Find Your Deleted User

In order to restore the user, you first have to find them.  To do this, you have to use the Get-AdObject command, which if you’ve used it before, you know how frustrating it can be sometimes.

Get-AdUser -Filter ‘ObjectClass -eq “User” -AND IsDeleted -eq $True -IncludeDeletedObjects -Properties IsDeleted, LastKnownParent | fl

The command above will find deleted user objects, and show you not only the name, but the LastKnownParent (last known OU).  Once you have the list, you can add more items to the filter list to narrow down your search, and then pipe the results to the restore command.

Restore Your Deleted User

Now that you’ve found your user, restoring is simple.  You can simply pipe the results to the Restore-AdObject command.

Get-AdUser -Filter ‘ObjectClass -eq “User” -AND IsDeleted -eq $True -IncludeDeletedObjects -Properties IsDeleted, LastKnownParent | Restore-AdObject

This is the simplest way to perform the restore, and will put the object back into it’s last known OU in your AD tree.  There are many other ways to narrow down the users, or specify an alternate OU, but I wanted to cover the simplest possible scenario for people looking for a quick fix to their problem.   If there is demand for more info, I’ll write a follow up post, so let me know in the comments below.

Leave a Reply


%d bloggers like this: