Recovering AD Users and Computers

Periodically I find myself needing to recover a user or computer that has been deleted from Active Directory, and every time I go Googling.  When I finally find the solution, I have to sit back and ask myself, why do I not document this.  So here it is, my documentation on recovering a deleted user or computer.  Enjoy.

Requirements:

  • Windows Server 2008 or 2008 R2
  • Active Directory 2008 or 2008 R2
  • Active Directory Module for Windows PowerShell (obtained through the Add Features in the Server Manager tool on Domain Controller)

Process:

  • Open Active Directory Module for Windows Powershell as administrator.
  • Now utilize the Get-ADObject command.

Searching for Users or Computers:

Search for a particular user

Get-ADObject -Filter {Deleted -eq $True -and Name -like "username" -and ObjectClass -eq "User"} -IncludeDeletedObjects

Search for a particular computer

Get-ADObject -Filter {Deleted -eq $True -and Name -like "computername" -and ObjectClass -eq "Computer"} -IncludeDeletedObjects

Note: Asterisks can used in the filter.  “*username*” and your filter can be as simple or as complex as you need.  As long as you include the -IncludeDeletedObjects parameter you should be good to go.

Restoring a User or Computer:

Once you use one of the above commands to locate the user or computer you want to restore, then pipe Restore-ADObject to the end of the statement.  Examples below.  Please make sure your results in your search are the only objects you want restored.

Restore a particular user

Get-ADObject -Filter {Deleted -eq $True -and Name -like "username" -and ObjectClass -eq "User"} -IncludeDeletedObjects | Restore-ADObject

Restore a particular computer

Get-ADObject -Filter {Deleted -eq $True -and Name -like "computername" -and ObjectClass -eq "Computer"} -IncludeDeletedObjects | Restore-ADObject

Restoring other AD Objects:

This method can also be used to restore other deleted objects in AD.  In order to do that you will need to edit the filter to return the needed object.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: